From afe24fa86d6bce45d95abb21f4948432cb4ed064 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Mon, 7 Dec 2015 16:32:03 +0100 Subject: [PATCH] Analog --- basic/pwm/pwm_0_manuale/pwm_0_manuale.ino | 2 +- .../pwm/pwm_1_while_byte/pwm_1_while_byte.ino | 5 ++- basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino | 40 ++++++++++++++++--- .../pwm_3_fade_reverser.ino | 3 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino b/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino index 12adae7..2170417 100644 --- a/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino +++ b/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino @@ -20,8 +20,8 @@ void loop() { brilla(); // microBrilla(); + } -///////////////////////////// // Funzioni personali void brilla() { 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 3f6de46..fed4e7f 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 @@ -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() { 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 d389ad1..610d302 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 @@ -6,12 +6,12 @@ */ -int led = 9; // Pin per il PWM +int led = 9; // Pin per il PWM +int pausa = 5; void setup() { pinMode(led, OUTPUT); - } void loop() @@ -22,15 +22,45 @@ void loop() 3. incremento operatore */ analogWrite(led, i) ; - delay(5 ); + delay(pausa); } // Ora l'inverso - for (int c = 255; c > 0 ; c--) { + for (int c = 255; c > 0 ; c--) { // Domanda: 1. avrei potuto usare come + // variabile di nuovo i ? analogWrite(led, c) ; - delay(5); + delay(pausa); } } +/* Domande: + 2. I due loop sembrano molto simili: e' possibile accorparli? + + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + - Risposte: + 1. Si, le variabili i e c esistono solo nello scopo degli iteratori + in cui sono dichiarate. + 2. Vedi es. suciessivo. + */ + 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 5112951..a6ad7d8 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 @@ -30,7 +30,8 @@ void loop() { fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect - delay(30); + delay(30); // Question: should this value be here? + // Would it be better to have a variable for it? Why? } -- 2.39.2