]> git.piffa.net Git - sketchbook_andrea/blob - piezo/keyboard_three_pullup_buttons/keyboard_three_pullup_buttons.ino
1bd4e47c994c58fb0388c49b223e0e3751334c46
[sketchbook_andrea] / piezo / keyboard_three_pullup_buttons / keyboard_three_pullup_buttons.ino
1 /*
2  Melody keyboard with Input Pullup Serial
3  Plays a pitch that changes based on 3 digital inputs
4  
5  This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a 
6  digital input on pin 2 and prints the results to the serial monitor.
7   
8  Thecircuit:
9  * 3 buttons in pin 2,3,4 with no resistors
10  * Piezo on digital pin 9
11  * Serial debug is available
12  
13  This example code is in the public domain
14  
15  */
16
17 // Please take care of the include path
18 #include "/root/arduino/sketchbook-lessons/piezo_mario_tune/pitches.h";
19 int input[]= {1,2,3};
20   int notes[] = {
21   NOTE_A4, NOTE_C4,NOTE_E3 };
22
23 void setup(){
24   //start serial connection
25   Serial.begin(9600);
26   //configure pin2 as an input and enable the internal pull-up resistor
27   pinMode(2, INPUT_PULLUP);
28   pinMode(3, INPUT_PULLUP);
29   pinMode(4, INPUT_PULLUP);
30   pinMode(9, OUTPUT); 
31
32
33 }
34
35 void loop(){
36  for (int thisSensor = 2; thisSensor < 5; thisSensor++) {
37    int sensorReading = digitalRead(thisSensor);
38    if (sensorReading == LOW) {
39      Serial.println(thisSensor);
40      tone(9, notes[thisSensor -2], 50); // Notes array is translated
41    }
42    //delay(2);
43  }
44 }
45
46
47