X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=basic%2Fpwm%2Fpwm_0_stati%2Fpwm_0_stati.ino;h=3863c4a8a3ad19ec4c3351c2962396b7a8e2033d;hb=6546e84b197a1c8e33b4bbd206dd4d31c664d99b;hp=6a54caca9a92a44938d308b45772a793ba96e346;hpb=7d6f74284a3cd2c880a7f9119f21bc46d6b6d407;p=sketchbook_andrea diff --git a/basic/pwm/pwm_0_stati/pwm_0_stati.ino b/basic/pwm/pwm_0_stati/pwm_0_stati.ino index 6a54cac..3863c4a 100644 --- a/basic/pwm/pwm_0_stati/pwm_0_stati.ino +++ b/basic/pwm/pwm_0_stati/pwm_0_stati.ino @@ -1,21 +1,37 @@ /* - PWM demo + PWM Stati PWM per un LED: impostare i valori di luminosita' di un LED. + 4 stati di luminosita' per un LED collegato a un PIN PWM */ -int led = 9 ; // Il pin ~9 e' abilitato al PWM -byte brightness = 0; // Valore iniziale per il PWM del LED -int pausa = 5; // Pausa tra uno stato e l'altro +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() { pinMode(led, OUTPUT); // Il PIN nove va dichiarato come un OUTPUT } void loop() { - analogWrite(led, brightness) ; // spento + // OUTPUT al 100% : 255 + analogWrite(led, brightness) ; delay(pausa); - brightness++ ; + // OUTPUT al 75% : 191 + analogWrite(led, brightness * 0.75) ; + delay(pausa); + + // OUTPUT al 50% : 127 + analogWrite(led, brightness * 0.5) ; + delay(pausa); + + // OUTPUT al 25%: 63 + analogWrite(led, brightness * 0.25 ) ; + delay(pausa); + + // OUTPUT al 0% + analogWrite(led, brightness * 0) ; + delay(pausa); }