#define gloveInput1 3 #define gloveInput2 5 #define gloveInput3 7 #define gloveInput4 8 #define gloveInput5 10 #define gloveInput6 12 #define led 13 #define speakerPin 1 int tempo = 1; void playTone(int tone, int duration) { for (long i = 0; i < duration * 90000L; i += tone * 2) { digitalWrite(speakerPin, HIGH); delayMicroseconds(tone); digitalWrite(speakerPin, LOW); delayMicroseconds(tone); } } void playNote(char note, int duration) { char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; // play the tone corresponding to the note name for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } // the setup routine runs once when you press reset: void setup() { // initialize the speaker pin as an output. pinMode(speakerPin, OUTPUT); pinMode(gloveInput1, INPUT); pinMode(gloveInput2, INPUT); pinMode(gloveInput3, INPUT); pinMode(gloveInput4, INPUT); pinMode(gloveInput5, INPUT); pinMode(gloveInput6, INPUT); digitalWrite(gloveInput1, HIGH); // turn on pullup resistors digitalWrite(gloveInput2, HIGH); // turn on pullup resistors digitalWrite(gloveInput3, HIGH); // turn on pullup resistors digitalWrite(gloveInput4, HIGH); // turn on pullup resistors digitalWrite(gloveInput5, HIGH); // turn on pullup resistors digitalWrite(gloveInput6, HIGH); // turn on pullup resistors } // the loop routine runs over and over again forever: void loop() { if(digitalRead(gloveInput1) == LOW){ playNote('c', tempo); } else if(digitalRead(gloveInput2) == LOW){ playNote('d', tempo); } else if(digitalRead(gloveInput3) == LOW){ playNote('e', tempo); } else if(digitalRead(gloveInput4) == LOW){ playNote('f', tempo); } else if(digitalRead(gloveInput5) == LOW){ playNote('g', tempo); } else if(digitalRead(gloveInput6) == LOW){ playNote('a', tempo); } delayMicroseconds(50); }