From: Andrea Manni Date: Mon, 23 Mar 2015 16:40:34 +0000 (+0100) Subject: PWM: errata and states X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=8bbff1c558947ca1ff1733240827c87494ff4fd5;p=sketchbook_andrea PWM: errata and states --- diff --git a/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino b/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino index 1d60d73..2a26de6 100644 --- a/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino +++ b/basic/buttons/button_presses_count_down_5/button_presses_count_down_5.ino @@ -1,5 +1,10 @@ /* - * Alternating switch + * Contatore di input + + Il programma rileva la pressione del bottone e + riduce un contatore ad ogni pressione, + passando dallo stato iniziale a un secondo stato finale + dopo 10 iterazioni. */ int switchPin = 2; // switch is connected to pin 2 diff --git a/basic/buttons/button_state_3/button_state_3.ino b/basic/buttons/button_state_3/button_state_3.ino index c008ff1..83b274f 100644 --- a/basic/buttons/button_state_3/button_state_3.ino +++ b/basic/buttons/button_state_3/button_state_3.ino @@ -19,7 +19,7 @@ void setup() { void loop(){ statoAttuale = digitalRead(switchPin); // Legge lo stato del bottone e lo resistra in val - // delay(20) // riduce l'effetto bounce + delay(20) // riduce l'effetto bounce if (statoAttuale != ultimoStato) { // lo stato del bottone e' cambiato if (statoAttuale == HIGH) { // il bottone e' stato premuto Serial.println("Bottone premuto"); diff --git a/basic/pwm/pwm_0_stati/pwm_0_stati.ino b/basic/pwm/pwm_0_stati/pwm_0_stati.ino new file mode 100644 index 0000000..f2c78a5 --- /dev/null +++ b/basic/pwm/pwm_0_stati/pwm_0_stati.ino @@ -0,0 +1,26 @@ +/* + PWM demo + + PWM per un LED: impostare i valori di luminosita' di un LED. + */ + +int led = 9 ; // Il pin ~9 e' abilitato al PWM +byte brightness = 0; // Valore iniziale per il PWM del LED +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, 0) ; // spento + delay(pausa); + analogWrite(led, 63) ; // 1/4 + delay(pausa); + analogWrite(led, 127) ; // 1/2 + delay(pausa); + analogWrite(led, 191) ; // 3/4 + delay(pausa); + analogWrite(led, 254) ; // Full light + delay(pausa); +} diff --git a/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino b/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino index de1a994..cf5451a 100644 --- a/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino +++ b/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino @@ -1,4 +1,4 @@ -/*pwm_ +/* Fade PWM per un LED: aumentare progressivamente la luminosita'. @@ -24,4 +24,4 @@ void loop() { 1. Come fare a invertire la dissolvenza diminuendo la luminosita'? 2. Provare a far salire e poi scendere la luminosita' - +*/ diff --git a/basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino b/basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino index 12e6e78..d389ad1 100644 --- a/basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino +++ b/basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino @@ -16,7 +16,7 @@ void setup() void loop() { - for ( i = 0; i < 255 ; i++) { // Operatore ternario, 3 argomenti: + for (int i = 0; i < 255 ; i++) { // Operatore ternario, 3 argomenti: /* 1. definizione iteratore 2. limite iteratore 3. incremento operatore @@ -25,9 +25,9 @@ void loop() delay(5 ); } // Ora l'inverso - for ( c = 255; c > 0 ; c--) { + for (int c = 255; c > 0 ; c--) { analogWrite(led, c) ; - delay(5 ); + delay(5); } } diff --git a/basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino b/basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino index 54cbb43..5112951 100644 --- a/basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino +++ b/basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino @@ -8,7 +8,7 @@ Fade */ int led = 9; -int brightness = 0; +int brightness = 0; // this two could be bytes as well int fadeAmount = 5; // the pin that the LED is attached to // how bright the LED is