1 /* Blink without Delay - due led
3 Turns on and off a light emitting diode(LED) connected to a digital
4 pin, without using the delay() function. This means that other code
5 can run at the same time without being interrupted by the LED code.
8 * LED attached from pin 13 to ground.
9 * Note: on most Arduinos, there is already an LED on the board
10 that's attached to pin 13, so no hardware is needed for this example.
19 This example code is in the public domain.
22 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
25 // constants won't change. Used here to
27 const int ledA = 13; // Primo LED
28 const int ledB = 12; // Secondo LED
30 // Variabbili di stato
31 int ledStateA = LOW; // ledState used to set the LED
32 int ledStateB = LOW; // ledState used to set the LED
34 long previousMillisA = 0; // will store last time LED was updated
35 long previousMillisB = 0; // will store last time LED was updated
37 // the follow variables is a long because the time, measured in miliseconds,
38 // will quickly become a bigger number than can be stored in an int.
39 long intervalA = 1000; // interval at which to blink (milliseconds)
40 long intervalB = 500; // interval at which to blink (milliseconds)
43 // set the digital pin as output:
44 pinMode(ledA, OUTPUT);
45 pinMode(ledB, OUTPUT);
51 if (millis() > previousMillisA + intervalA) {
52 // save the last time you blinked the LED
53 previousMillisA = millis();
55 // if the LED is off turn it on and vice-versa:
60 // set the LED with the ledState of the variable:
61 digitalWrite(ledA, ledStateA);
65 if (millis() > previousMillisB + intervalB) {
66 // save the last time you blinked the LED
67 previousMillisB = millis();
69 // if the LED is off turn it on and vice-versa:
74 // set the LED with the ledState of the variable:
75 digitalWrite(ledB, ledStateB);
80 1. Provare a isolare il codice per accendere ogni singolo led in una funzione:
81 - Quali variabili determinano il comportamento del LED?
82 - Come cambiano durante il corso dello script?
83 - Sono globali o locali?
84 - Quali parti vanno eseguite una sola volta e quali a ogni esecuzione?