source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 3 years ago

Adding new version

File size: 1.3 KB
Line 
1/*
2  Arduino Starter Kit example
3 Project 7  - Keyboard
4
5 This sketch is written to accompany Project 7 in the
6 Arduino Starter Kit
7
8 Parts required:
9 two 10 kilohm resistors
10 1 Megohm resistor
11 220 ohm resistor
12 4 pushbuttons
13 piezo
14
15 Created 13 September 2012
16 by Scott Fitzgerald
17
18 http://www.arduino.cc/starterKit
19
20 This example code is part of the public domain
21*/
22
23// create an array of notes
24// the numbers below correspond to
25// the frequencies of middle C, D, E, and F
26int notes[] = {262, 294, 330, 349};
27
28void setup() {
29  //start serial communication
30  Serial.begin(9600);
31}
32
33void loop() {
34  // create a local variable to hold the input on pin A0
35  int keyVal = analogRead(A0);
36  // send the value from A0 to the Serial Monitor
37  Serial.println(keyVal);
38
39  // play the note corresponding to each value on A0
40  if (keyVal == 1023) {
41    // play the first frequency in the array on pin 8
42    tone(8, notes[0]);
43  } else if (keyVal >= 990 && keyVal <= 1010) {
44    // play the second frequency in the array on pin 8
45    tone(8, notes[1]);
46  } else if (keyVal >= 505 && keyVal <= 515) {
47    // play the third frequency in the array on pin 8
48    tone(8, notes[2]);
49  } else if (keyVal >= 5 && keyVal <= 10) {
50    // play the fourth frequency in the array on pin 8
51    tone(8, notes[3]);
52  } else {
53    // if the value is out of range, play no tone
54    noTone(8);
55  }
56}
57
Note: See TracBrowser for help on using the repository browser.