Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- //A
- int buttonPin2 = 2;
- int Anote = NOTE_A3;
- int ADurat = 8;
- //B
- int buttonPin3 = 3;
- int Bnote = NOTE_B3;
- int BDurat = 8;
- //C
- int buttonPin4 = 4;
- int Cnote = NOTE_C4;
- int CDurat = 8;
- //D
- int buttonPin5 = 5;
- int Dnote = NOTE_D4;
- int DDurat = 8;
- //E
- int buttonPin6 = 6;
- int Enote = NOTE_E4;
- int EDurat = 8;
- //F
- int buttonPin7 = 7;
- int Fnote = NOTE_F4;
- int FDurat = 8;
- //G
- int buttonPin8 = 8;
- int Gnote = NOTE_G4;
- int GDurat = 8;
- void setup(){
- pinMode(buttonPin2, INPUT);
- pinMode(buttonPin3, INPUT);
- pinMode(buttonPin4, INPUT);
- pinMode(buttonPin5, INPUT);
- pinMode(buttonPin6, INPUT);
- pinMode(buttonPin7, INPUT);
- pinMode(buttonPin8, INPUT);
- }
- void loop(){
- int buttonState2 = digitalRead(buttonPin2); //A
- int buttonState3 = digitalRead(buttonPin3); //B
- int buttonState4 = digitalRead(buttonPin4); //C
- int buttonState5 = digitalRead(buttonPin5); //D
- int buttonState6 = digitalRead(buttonPin6); //E
- int buttonState7 = digitalRead(buttonPin7); //F
- int buttonState8 = digitalRead(buttonPin8); //G
- //A
- if (buttonState2 == 1){
- int noteDuration = 2000 / ADurat;
- tone(12, Anote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //B
- if (buttonState3 == 1){
- int noteDuration = 2000 / BDurat;
- tone(12, Bnote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //C
- if (buttonState4 == 1){
- int noteDuration = 2000 / CDurat;
- tone(12, Cnote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //D
- if (buttonState5 == 1){
- int noteDuration = 2000 / DDurat;
- tone(12, Dnote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //E
- if (buttonState6 == 1){
- int noteDuration = 2000 / EDurat;
- tone(12, Enote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //F
- if (buttonState7 == 1){
- int noteDuration = 2000 / FDurat;
- tone(12, Fnote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- //G
- if (buttonState8 == 1){
- int noteDuration = 2000 / GDurat;
- tone(12, Gnote, noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement