]> git.piffa.net Git - sketchbook_andrea/blobdiff - basic/analog_input/photo_3_serial/photo_3_serial.ino
Data type con funzione
[sketchbook_andrea] / basic / analog_input / photo_3_serial / photo_3_serial.ino
index 2266237cab2df3d23b7d47d47bbe10c9322d9795..22c070f72bfeba4d662661333fb739274ad84686 100644 (file)
@@ -1,6 +1,6 @@
 /*
   Photoresistor
 /*
   Photoresistor
-  
  Utilizzare una fotoresistenza come analog input.
  Il comportamento della foto resistenza e' simile
  a un potenziometro: varia la resistenza in base alla 
  Utilizzare una fotoresistenza come analog input.
  Il comportamento della foto resistenza e' simile
  a un potenziometro: varia la resistenza in base alla 
  
  Questo sketch modifica l'intervallo di intermittenza di un led
  in base alla luminosita' rilevata.
  
  Questo sketch modifica l'intervallo di intermittenza di un led
  in base alla luminosita' rilevata.
+ Schema: http://lab.piffa.net/schemi/photoresistor_led.png
+ Guida:  https://learn.adafruit.com/photocells/using-a-photocell
  */
 
  */
 
-int sensorPin = A0;    // select the input pin for the potentiometer
-int ledPin = 13;      // select the pin for the LED
+int sensorPin = A0;   // select the input pin for the potentiometer
+int ledPin = 3;      // 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);  
 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:
+  // initialize serial communications at 9600 bps:
   Serial.begin(9600); 
 }
 
   Serial.begin(9600); 
 }
 
@@ -34,7 +37,7 @@ void loop() {
   // turn the ledPin off:        
   digitalWrite(ledPin, LOW);   
   // stop the program for for <sensorValue> milliseconds:
   // turn the ledPin off:        
   digitalWrite(ledPin, LOW);   
   // stop the program for for <sensorValue> milliseconds:
-    // print the results to the serial monitor:
+  // print the results to the serial monitor:
   Serial.print("sensor = " );                       
   Serial.print(sensorValue);      
   Serial.print("\t delay = ");      
   Serial.print("sensor = " );                       
   Serial.print(sensorValue);      
   Serial.print("\t delay = ");      
@@ -43,8 +46,10 @@ void loop() {
 }
 
 /* domande:
 }
 
 /* domande:
-1. qual'e' il valore minimo rilevato?
-2. quale il massimo?
-3. Come adattare la risoluzione dell'attuatore alla sensibilita' del sensore?
-*/
+ 1. qual'e' il valore minimo rilevato?
+ 2. quale il massimo?
+ 3. Modificare lo sketch in modo che modifichi la luminosita' di un LED 
+via PWM tramite il valore letto dal sensore. (vedi esercizio sucessivo)
+ */
+