X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=basic%2Fpwm%2Fpwm_3_fade_reverser%2Fpwm_3_fade_reverser.ino;h=9a0860aafce77ad33932d9e3f23cc8b7fad036ff;hb=6546e84b197a1c8e33b4bbd206dd4d31c664d99b;hp=54cbb433e0dbdd4386171bdd098b3ea9c17c2628;hpb=e50f2cf8e7402ea56cd01835be9f88c53876bfd1;p=sketchbook_andrea 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..9a0860a 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,34 +7,58 @@ Fade From Arduino for dummies. */ -int led = 9; -int brightness = 0; -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' +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); + 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 + +*/