4 Utilizzare una fotoresistenza come analog input.
5 Il comportamento della foto resistenza e' simile
6 a un potenziometro: varia la resistenza in base alla
9 Per ottenere valori significativi utilizzare unaresistenza
10 da ~5k ohms in serie con il sensore.
12 Questo sketch modifica l'intervallo di intermittenza di un led
13 in base alla luminosita' rilevata.
15 Schema: http://lab.piffa.net/schemi/photoresistor_led.png
16 Guida: https://learn.adafruit.com/photocells/using-a-photocell
19 int sensorPin = A0; // select the input pin for the potentiometer
20 int ledPin = 3; // select the pin for the LED
21 int sensorValue = 0; // variable to store the value coming from the sensor
24 // declare the ledPin as an OUTPUT:
25 pinMode(ledPin, OUTPUT);
26 // initialize serial communications at 9600 bps:
31 // read the value from the sensor:
32 sensorValue = analogRead(sensorPin);
34 digitalWrite(ledPin, HIGH);
35 // stop the program for <sensorValue> milliseconds:
37 // turn the ledPin off:
38 digitalWrite(ledPin, LOW);
39 // stop the program for for <sensorValue> milliseconds:
40 // print the results to the serial monitor:
41 Serial.print("sensor = " );
42 Serial.print(sensorValue);
43 Serial.print("\t delay = ");
44 Serial.println(sensorValue);
49 1. qual'e' il valore minimo rilevato?
51 3. Modificare lo sketch in modo che modifichi la luminosita' di un LED
52 via PWM tramite il valore letto dal sensore. (vedi esercizio sucessivo)