1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-12 23:08:52 +01:00
Arduino/build/shared/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino

57 lines
1.4 KiB
Arduino
Raw Normal View History

2012-10-12 19:23:48 +02:00
/*
Arduino Starter Kit example
Project 7 - Keyboard
This sketch is written to accompany Project 7 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
1 Megohm resistor
220 ohm resistor
4 pushbuttons
piezo
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
This example code is part of the public domain
2012-10-12 19:23:48 +02:00
*/
// create an array of notes
// the numbers below correspond to
2012-10-12 19:23:48 +02:00
// the frequencies of middle C, D, E, and F
int notes[] = {262, 294, 330, 349};
void setup() {
//start serial communication
2012-10-12 19:23:48 +02:00
Serial.begin(9600);
}
void loop() {
// create a local variable to hold the input on pin A0
int keyVal = analogRead(A0);
// send the value from A0 to the Serial Monitor
Serial.println(keyVal);
2012-10-12 19:23:48 +02:00
// play the note corresponding to each value on A0
if (keyVal == 1023) {
2012-10-12 19:23:48 +02:00
// play the first frequency in the array on pin 8
tone(8, notes[0]);
} else if (keyVal >= 990 && keyVal <= 1010) {
2012-10-12 19:23:48 +02:00
// play the second frequency in the array on pin 8
tone(8, notes[1]);
} else if (keyVal >= 505 && keyVal <= 515) {
2012-10-12 19:23:48 +02:00
// play the third frequency in the array on pin 8
tone(8, notes[2]);
} else if (keyVal >= 5 && keyVal <= 10) {
2012-10-12 19:23:48 +02:00
// play the fourth frequency in the array on pin 8
tone(8, notes[3]);
} else {
2012-10-12 19:23:48 +02:00
// if the value is out of range, play no tone
noTone(8);
}
}