X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=basic%2Fpwm%2Fpwm_0_stati%2Fpwm_0_stati.ino;fp=basic%2Fpwm%2Fpwm_0_stati%2Fpwm_0_stati.ino;h=7842b6cc2d981061b2b55c5e91b417e100cd2fac;hp=3863c4a8a3ad19ec4c3351c2962396b7a8e2033d;hb=3186569da93182e73fa3ea99beb8c9ea53a6ba8a;hpb=7235b2bd6847d70a486c4941ed3d4fc3186d02de diff --git a/basic/pwm/pwm_0_stati/pwm_0_stati.ino b/basic/pwm/pwm_0_stati/pwm_0_stati.ino index 3863c4a..7842b6c 100644 --- a/basic/pwm/pwm_0_stati/pwm_0_stati.ino +++ b/basic/pwm/pwm_0_stati/pwm_0_stati.ino @@ -3,11 +3,13 @@ PWM per un LED: impostare i valori di luminosita' di un LED. 4 stati di luminosita' per un LED collegato a un PIN PWM + + Il PWM del 328p simula un convertitore digitale -> analogico + con profondita' di 8 bit: 256 valori da 0 - 255 . */ const int led = 9 ; // Il pin ~9 e' abilitato al PWM -byte brightness = 255; // Valore iniziale per il PWM del LED const int pausa = 2000; // Pausa tra uno stato e l'altro void setup() { @@ -16,22 +18,22 @@ void setup() { void loop() { // OUTPUT al 100% : 255 - analogWrite(led, brightness) ; + analogWrite(led, 255) ; delay(pausa); // OUTPUT al 75% : 191 - analogWrite(led, brightness * 0.75) ; + analogWrite(led, 191) ; delay(pausa); // OUTPUT al 50% : 127 - analogWrite(led, brightness * 0.5) ; + analogWrite(led, 127) ; delay(pausa); // OUTPUT al 25%: 63 - analogWrite(led, brightness * 0.25 ) ; + analogWrite(led, 63 ) ; delay(pausa); // OUTPUT al 0% - analogWrite(led, brightness * 0) ; + analogWrite(led, 0) ; delay(pausa); }