X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=basic%2Fanalog_input%2Fphoto_3_serial%2Fphoto_3_serial.ino;fp=basic%2Fanalog_input%2Fphoto_3_serial%2Fphoto_3_serial.ino;h=2266237cab2df3d23b7d47d47bbe10c9322d9795;hb=db26862cf5427076e1b6c05b5624f3e72b307f41;hp=0000000000000000000000000000000000000000;hpb=8f9853f962b96d5b01e1db7cef031783c851c8dc;p=sketchbook_andrea diff --git a/basic/analog_input/photo_3_serial/photo_3_serial.ino b/basic/analog_input/photo_3_serial/photo_3_serial.ino new file mode 100644 index 0000000..2266237 --- /dev/null +++ b/basic/analog_input/photo_3_serial/photo_3_serial.ino @@ -0,0 +1,50 @@ +/* + Photoresistor + + Utilizzare una fotoresistenza come analog input. + Il comportamento della foto resistenza e' simile + a un potenziometro: varia la resistenza in base alla + quantita' di luce. + + Per ottenere valori significativi utilizzare unaresistenza + da ~5k ohms in serie con il sensore. + + Questo sketch modifica l'intervallo di intermittenza di un led + in base alla luminosita' rilevata. + */ + +int sensorPin = A0; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int sensorValue = 0; // variable to store the value coming from the sensor + +void setup() { + // declare the ledPin as an OUTPUT: + pinMode(ledPin, OUTPUT); + // initialize serial communications at 9600 bps: + Serial.begin(9600); +} + +void loop() { + // read the value from the sensor: + sensorValue = analogRead(sensorPin); + // turn the ledPin on + digitalWrite(ledPin, HIGH); + // stop the program for milliseconds: + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); + // stop the program for for milliseconds: + // print the results to the serial monitor: + Serial.print("sensor = " ); + Serial.print(sensorValue); + Serial.print("\t delay = "); + Serial.println(sensorValue); + delay(sensorValue); +} + +/* domande: +1. qual'e' il valore minimo rilevato? +2. quale il massimo? +3. Come adattare la risoluzione dell'attuatore alla sensibilita' del sensore? +*/ +