3 Melody keyboard with Input Pullup
4 Plays a pitch that changes based on 3 digital inputs
6 This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
7 digital input on pin 2 and prints the results to the serial monitor.
8 There's also an extensive use of arrays.
11 * 3 buttons in pin 2,3,4 with no resistors
12 * Piezo on digital pin 9
13 * Serial debug is available
15 This example code is in the public domain
17 Circuit: http://lab.piffa.net/schemi/piezo_2_keyboard_bb.png
21 const int tasti[]= {4,3,2}; // La nota piu' a sx e' quella piu' bassa
22 const int notes[] = {262, 392, 880}; // suona una prima, quinta, ottava in C4
23 const int piezo_pin = 9;
25 // Carica un file di esempio con tutte le note
26 // #include "pitches.h";
27 // int notes[] = {NOTE_C4, NOTE_G4,NOTE_C5 }; // suona una prima, quinta, ottava
30 //start serial connection
32 Serial.println("Welcome");
33 //configure pin2/3/4 as an input and enable the internal pull-up resistor
34 pinMode(tasti[0], INPUT_PULLUP);
35 pinMode(tasti[1], INPUT_PULLUP);
36 pinMode(tasti[2], INPUT_PULLUP); // Provare ad impostare i PIN con un
42 for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
43 int sensorReading = digitalRead(tasti[thisSensor]);
44 if (sensorReading == LOW) {
45 Serial.print("Sensore: ");
46 Serial.print(thisSensor);
47 tone(piezo_pin, notes[thisSensor ], 50); // Notes array is translated
48 Serial.print("\t Nota: ");
49 Serial.println(notes[thisSensor]);
51 //delay(2); // eventuale delay
55 1. Modificare le note suonate utilizzando come riferimento il file pitches.h:
56 suonare una prima, terza, quinta (C-E-G)
57 2. Includere il file pitches.h . Come si potrebbe scrivere una melodia da far s uonare autnomamente ad Arduino?