// Stepper - Version: Latest
#include<Servo.h>
int button1 = 5;
int button2 = 6;
int bnoise1 = 11;
int bnoise2 = 12;
int bnoise3 = 2;
int bnoise4 = 3;
int bnoise5 = 4; //Definesthe variables and assighnes them to the needed pins
int buzzerpin = 7;
int buzzerpin1 = 8;
int buzzerpin2 = 9;
int botservo;
int topservo;
int botservo2;
int servon = 160;
int servof = 0;
void setup() {
pinMode(bnoise1, INPUT_PULLUP);
pinMode(bnoise2, INPUT_PULLUP);
pinMode(bnoise3, INPUT_PULLUP);
pinMode(bnoise4, INPUT_PULLUP);
pinMode(bnoise5, INPUT_PULLUP);
pinMode(button1, INPUT_PULLUP); //sets the objects as a input(button) or output(speaker)
pinMode(button2, INPUT_PULLUP);
pinMode(buzzerpin, OUTPUT);
pinMode(buzzerpin1, OUTPUT);
pinMode(buzzerpin2, OUTPUT);
}
void loop() {
if (digitalRead(button1) == LOW){ //If the catagory button is pressed, assign notes to the piano buttons
if (digitalRead(bnoise1) == LOW){ //When first button is pressed play D
tone(buzzerpin,147); //D
}
else if (digitalRead(bnoise2) == LOW){ //When second button is pressed play G
tone(buzzerpin,196); //G
}
else if (digitalRead(bnoise3) == LOW){ //When third button is pressed play A
tone(buzzerpin, 220); //A
}
else if (digitalRead(bnoise4) == LOW){ //When Fourth button is pressed play B
tone(buzzerpin, 247); //B
}
else if(digitalRead(bnoise5)==LOW){ //When fith button is pressed play D
tone(buzzerpin, 292); //D
}
else{
noTone(buzzerpin);
noTone(buzzerpin1); // If nothis is pressed turn off speaker
}
}else if(digitalRead(button2) == LOW){
if (digitalRead(bnoise1) == LOW){ //same as above but with diffrent notes
tone(buzzerpin, 131);//C
}
if (digitalRead(bnoise1) == LOW){
tone(buzzerpin, 165);//E
}
if (digitalRead(bnoise1) == LOW){
tone(buzzerpin, 196);//G
}
if (digitalRead(bnoise1) == LOW){
tone(buzzerpin, 220);//A
}
if (digitalRead(bnoise1) == LOW){
tone(buzzerpin, 247);//B
}
else{
noTone(buzzerpin); //else plays no ton
}
}
}
Warning over 300 lines of code will pop up when opened