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 - 10k 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
18 int sensorPin = A0; // select the input pin for the potentiometer
19 int ledPin = 13; // select the pin for the LED
20 int sensorValue = 0; // variable to store the value coming from the sensor
22 int min = 60; // valore minimo rilevato dal sensore
23 int max = 600; // valore massimo rilevato dal sensore
26 // declare the ledPin as an OUTPUT:
27 pinMode(ledPin, OUTPUT);
28 // initialize serial communications at 9600 bps:
33 // read the value from the sensor:
34 sensorValue = analogRead(sensorPin);
35 int calValue = map(sensorValue,min,max,0,1024) ;
38 digitalWrite(ledPin, HIGH);
39 // stop the program for <sensorValue> milliseconds:
41 // turn the ledPin off:
42 digitalWrite(ledPin, LOW);
43 // stop the program for for <sensorValue> milliseconds:
44 // print the results to the serial monitor:
45 Serial.print("sensor = " );
46 Serial.print(sensorValue);
47 Serial.print("\t cal delay = ");
48 Serial.println(calValue);
54 1. Modificare lo sketch in modo che modifichi la luminosita' di un led
55 via PWM tramite il valore letto dal sensore.
56 2. Come fare per costringere la variabile dentro un intervallo stabilito?
57 3. Come si potrebbe eseguire la calibrazione automaticamente?