]> git.piffa.net Git - sketchbook_andrea/blobdiff - basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino
State machine e blinks con millis()
[sketchbook_andrea] / basic / pwm / pwm_1_while_byte / pwm_1_while_byte.ino
index cf5451afd453f2657a708115b9463ebc024e4226..fed4e7f0e70c8c96bf4583e680aa5c53966cfcbc 100644 (file)
@@ -4,8 +4,9 @@
    PWM per un LED: aumentare progressivamente la luminosita'.
  */
 
-byte led  = 9   ;     // Il pin ~9 e' abilitato al PWM
-byte brightness = 0;  // Valore iniziale per il PWM del LED
+const byte led  = 9   ; // Il pin ~9 e' abilitato al PWM
+byte brightness = 0;    // Valore iniziale per il PWM del LED
+                        // Perche' brightness non e' una costante?
 
 // the setup routine runs once when you press reset:
 void setup()  { 
@@ -13,10 +14,11 @@ void setup()  {
 } 
 
 void loop()  { 
-  analogWrite(led, brightness++);  // La funziona analogWrite utilizza il PWM
+  analogWrite(led, brightness);  // La funziona analogWrite utilizza il PWM
   // a 8 bit integrato nel MCU: simula un serie di valori intermedi
   // nell'intervallo discreto con minimo 0 (spento) e  massimo 255 (acceso).         
   delay(10);       
+  brightness = brightness + 1; // Incrementiamo la luminosita'
 }
 
 /* Domande: