]> git.piffa.net Git - sketchbook_andrea/blob - basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino
688465f3c9c9c01fa80cc197d73656e7c012fce9
[sketchbook_andrea] / basic / pwm / pwm_3_fade_reverser / pwm_3_fade_reverser.ino
1 /*
2 Fade
3  
4  This example shows how to fade an LED on pin 9
5  using the analogWrite() function.
6  This example code is in the public domain.
7  From Arduino for dummies.
8  */
9
10 const int led = 9;          // LED con PWM
11 byte brightness = 0;        // Luminosita'
12 const int fadeAmount = 5;   // Step di modifica luminosita'
13 const int pause = 30;       // Pausa tra incrementi
14
15
16 void setup() {
17   pinMode(led, OUTPUT); // declare pin 9 to be an output:
18 }
19
20 void loop() {
21
22   analogWrite(led, brightness);
23   brightness = brightness + fadeAmount;
24
25   if (brightness == 0 || brightness == 255) {
26   // Invertire incremento ai valori limiti
27     fadeAmount = -fadeAmount ;
28   }
29   // wait for 30  milliseconds to see the dimming effect
30   delay(pause); 
31 }
32
33
34 /* Domande:
35    1. Che rapporto c'e' tra un OR e due cicli IF ?
36    2. E tra un AND e due cicli IF ?
37 .
38 .
39 .
40 .
41 .
42 .
43 .
44 .
45 .
46 .
47 .
48 .
49 .
50 .
51 .
52 .
53 .
54 .
55 .
56 .
57 Soluzioni:
58    1. Due cicli IF sequenziali con:
59     - Condizioni diverse
60     - stessa conseguenza
61
62    2. Due cicli IF annidiati che verificano due condizioni in sucessione
63    
64 /*