2 Melody keyboard with Input Pullup Serial
3 Plays a pitch that changes based on 3 digital inputs
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.
9 * 3 buttons in pin 2,3,4 with no resistors
10 * Piezo on digital pin 9
11 * Serial debug is available
13 This example code is in the public domain
15 Circuit: http://lab.piffa.net/schemi/piezo_2_keyboard_bb.png
23 262, 392,880 }; // suona una prima, quinta, ottava in C4
25 // Carica un file di esempio con tutte le note
26 // #include "pitches.h";
27 // int notes[] = {NOTE_C4, NOTE_G4,NOTE_A5 }; // suona una prima, quinta, ottava
30 //start serial connection
32 //configure pin2/3/4 as an input and enable the internal pull-up resistor
33 pinMode(2, INPUT_PULLUP);
34 pinMode(3, INPUT_PULLUP);
35 pinMode(4, INPUT_PULLUP);
40 for (int thisSensor = 2; thisSensor < 5; thisSensor++) {
41 int sensorReading = digitalRead(thisSensor);
42 if (sensorReading == LOW) {
43 Serial.println(thisSensor);
44 tone(9, notes[thisSensor -2], 50); // Notes array is translated
46 //delay(2); // eventuale delay
50 1. Modificare le note suonate utilizzando come riferimento il file pitches.h:
51 suonare una prima, terza, quinta (C-E-G)
52 2. Includere il file pitches.h . Come si potrebbe scrivere una melodia da far suonare
53 autnomamente ad Arduino?