Devices & Components
Arduino Uno Rev3
Through Hole Resistor, 560 ohm
Resistor 1k ohm
Tactile Switch, Top Actuated
Speaker, Piezo
Resistor 10k ohm
Jumper wires (generic)
Resistor 220 ohm
Resistor 4.7 kOhm
Project description
Code
Keyboard from the starter kit using 6 pushbuttons
arduino
Keyboard C, D, E, F, G, A
1 2// create an array of notes 3// the numbers below correspond to the frequencies of middle C, D, E, F, G and A 4int notes[] = {262, 294, 330, 349, 392, 440}; 5 6void setup() { 7 //start serial communication 8 Serial.begin(9600); 9} 10 11void loop() { 12 // create a local variable to hold the input on pin A0 13 int keyVal = analogRead(A0); 14 // send the value from A0 to the Serial Monitor 15 Serial.println(keyVal); 16 17 // play the note corresponding to each value on A0 (0 Ohm) 18 if (keyVal == 1023) { 19 // play the first frequency in the array on pin 8 20 tone(8, notes[0]); 21 } else if (keyVal >= 970 && keyVal <= 1010) { 22 // play the second frequency in the array on pin 8 (220 Ohm) 23 tone(8, notes[1]); 24 } else if (keyVal >= 900 && keyVal <= 920) { 25 // play the third frequency in the array on pin 8 (560 Ohm) 26 tone(8, notes[2]); 27 } else if (keyVal >= 840 && keyVal <= 850) { 28 // play the fourth frequency in the array on pin 8 (1 kOhm) 29 tone(8, notes[3]); 30 } else if (keyVal >= 500 && keyVal <= 520) { 31 // play the fourth frequency in the array on pin 8 (4.7 kOhm) 32 tone(8, notes[4]); 33 } else if (keyVal >= 300 && keyVal <= 350) { 34 // play the fourth frequency in the array on pin 8 (10 kOhm) 35 tone(8, notes[5]); 36 } else { 37 // if the value is out of range, play no tone 38 noTone(8); 39 } 40}
Keyboard from the starter kit using 6 pushbuttons
arduino
Keyboard C, D, E, F, G, A
1 2// create an array of notes 3// the numbers below correspond to the frequencies of middle C, D, E, F, G and A 4int notes[] = {262, 294, 330, 349, 392, 440}; 5 6void setup() { 7 //start serial communication 8 Serial.begin(9600); 9} 10 11void loop() { 12 // create a local variable to hold the input on pin A0 13 int keyVal = analogRead(A0); 14 // send the value from A0 to the Serial Monitor 15 Serial.println(keyVal); 16 17 // play the note corresponding to each value on A0 (0 Ohm) 18 if (keyVal == 1023) { 19 // play the first frequency in the array on pin 8 20 tone(8, notes[0]); 21 } else if (keyVal >= 970 && keyVal <= 1010) { 22 // play the second frequency in the array on pin 8 (220 Ohm) 23 tone(8, notes[1]); 24 } else if (keyVal >= 900 && keyVal <= 920) { 25 // play the third frequency in the array on pin 8 (560 Ohm) 26 tone(8, notes[2]); 27 } else if (keyVal >= 840 && keyVal <= 850) { 28 // play the fourth frequency in the array on pin 8 (1 kOhm) 29 tone(8, notes[3]); 30 } else if (keyVal >= 500 && keyVal <= 520) { 31 // play the fourth frequency in the array on pin 8 (4.7 kOhm) 32 tone(8, notes[4]); 33 } else if (keyVal >= 300 && keyVal <= 350) { 34 // play the fourth frequency in the array on pin 8 (10 kOhm) 35 tone(8, notes[5]); 36 } else { 37 // if the value is out of range, play no tone 38 noTone(8); 39 } 40}
Downloadable files
Keyboard 6 keys
Pimped up keyboard from the starter kit
Keyboard 6 keys
Comments
Only logged in users can leave comments