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://arduino.cc/en/Tutorial/Tone2
23 // initialize serial communications (for debugging only):
29 int sensorReading = analogRead(A0);
30 // print the sensor reading so you know its range
31 Serial.println(sensorReading);
32 // map the analog input range (in this case, 400 - 1000 from the photoresistor)
33 // to the output pitch range (120 - 1500Hz)
34 // change the minimum and maximum input numbers below
35 // depending on the range your sensor's giving:
36 int thisPitch = map(sensorReading, 400, 1000, 120, 1500);
39 tone(9, thisPitch, 10);
40 delay(1); // delay in between reads for stability
44 1. Modificare l'estensione del range di frequenza del piezo
45 tra i valori 20hz e 20.000hz.
47 2. Modificare lo script in modo che vengano emessi suoni solo quando
48 una mano offusca leggermente la luce (il piezo non deve suonare
49 se non c'e' un operatore a interagire con la fotoresistenza).