From: Andrea Manni Date: Mon, 21 Mar 2016 18:09:24 +0000 (+0100) Subject: Analog practice X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=0ef9dc22a6c180ef5470b5dd1389ba297a7d1e39;p=sketchbook_andrea Analog practice --- diff --git a/basic/analog_input/photo_5_calibration/photo_5_calibration.ino b/basic/analog_input/photo_5_calibration/photo_5_calibration.ino index ea8ecf8..1d9b4d7 100644 --- a/basic/analog_input/photo_5_calibration/photo_5_calibration.ino +++ b/basic/analog_input/photo_5_calibration/photo_5_calibration.ino @@ -54,6 +54,7 @@ void setup() { if (sensorValue < sensorMin) { sensorMin = sensorValue; } + delay(5); // Let the sensor rest a bit and stabilize } // signal the end of the calibration period 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 a6ad7d8..688465f 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 @@ -7,35 +7,58 @@ Fade From Arduino for dummies. */ -int led = 9; -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 -// how many points to fade the LED by -// the setup routine runs once when you press reset: +const int led = 9; // LED con PWM +byte brightness = 0; // Luminosita' +const int fadeAmount = 5; // Step di modifica luminosita' +const int pause = 30; // Pausa tra incrementi + void setup() { - // declare pin 9 to be an output: - pinMode(led, OUTPUT); + pinMode(led, OUTPUT); // declare pin 9 to be an output: } -// the loop routine runs over and over again forever: + void loop() { - // set the brightness of pin 9: + analogWrite(led, brightness); - // change the brightness for next time through the loop: brightness = brightness + fadeAmount; - // reverse the direction of the fading at the ends of the fade: + if (brightness == 0 || brightness == 255) { + // Invertire incremento ai valori limiti fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect - delay(30); // Question: should this value be here? - // Would it be better to have a variable for it? Why? + delay(pause); } +/* Domande: + 1. Che rapporto c'e' tra un OR e due cicli IF ? + 2. E tra un AND e due cicli IF ? +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +Soluzioni: + 1. Due cicli IF sequenziali con: + - Condizioni diverse + - stessa conseguenza - - - + 2. Due cicli IF annidiati che verificano due condizioni in sucessione + +/*