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.
16 int sensorPin = A0; // select the input pin for the potentiometer
17 int ledPin = 13; // select the pin for the LED
18 int sensorValue = 0; // variable to store the value coming from the sensor
20 int min = 240; // valore minimo rilevato dal sensore
21 int max = 380; // valore massimo rilevato dal sensore
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);
33 int calValue = map(sensorValue,min,max,0,1024) ;
36 digitalWrite(ledPin, HIGH);
37 // stop the program for <sensorValue> milliseconds:
39 // turn the ledPin off:
40 digitalWrite(ledPin, LOW);
41 // stop the program for for <sensorValue> milliseconds:
42 // print the results to the serial monitor:
43 Serial.print("sensor = " );
44 Serial.print(sensorValue);
45 Serial.print("\t delay = ");
46 Serial.println(calValue);
51 1. qual'e' il valore minimo rilevato?
53 3. Come adattare la risoluzione dell'attuatore alla sensibilita' del sensore?