4 Plays a pitch that changes based on a changing analog input
7 * 8-ohm speaker on digital pin 8
8 * photoresistor on analog 0 to 5V
9 * 4.7K resistor on analog 0 to ground
13 by Tom Igoe, with suggestion from Michael Flynn
15 This example code is in the public domain.
17 - http://www.dummies.com/how-to/content/how-to-make-an-instrument-with-the-arduino.html
18 - https://www.arduino.cc/en/Tutorial/tonePitchFollower
23 // These constants won't change:
24 const int sensorPin = A0; // pin that the sensor is attached to
25 const int ledPin = 9; // pin that the LED is attached to
29 // initialize serial communications (for debugging only):
35 int sensorReading = analogRead(sensorPin);
36 // print the sensor reading so you know its range
37 Serial.println(sensorReading);
38 // map the analog input range (in this case, 400 - 1000 from the photoresistor)
39 // to the output pitch range (120 - 1500Hz)
40 // change the minimum and maximum input numbers below
41 // depending on the range your sensor's giving:
42 int thisPitch = map(sensorReading, 300, 900, 220, 3500);
45 tone(ledPin, thisPitch, 10);
46 delay(1); // delay in between reads for stability
50 1. Modificare l'estensione del range di frequenza del piezo
51 tra i valori 20hz e 20.000hz.
52 2. Inserire l'auto calibrazione
53 3. Modificare lo script in modo che vengano emessi suoni solo quando
54 una mano offusca leggermente la luce (il piezo non deve suonare
55 se non c'e' un operatore a interagire con la fotoresistenza).