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.
18 This example code is in the public domain.
21 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
24 // constants won't change. Used here to
26 const int ledA = 13; // the number of the LED pin
27 int ledB = 12; //Secondo LED
29 // Variables will change:
30 int ledStateA = LOW; // ledState used to set the LED
31 int ledStateB = LOW; // ledState used to set the LED
33 long previousMillisA = 0; // will store last time LED was updated
34 long previousMillisB = 0; // will store last time LED was updated
36 // the follow variables is a long because the time, measured in miliseconds,
37 // will quickly become a bigger number than can be stored in an int.
38 long intervalA = 1000; // interval at which to blink (milliseconds)
39 long intervalB = 500; // interval at which to blink (milliseconds)
42 // set the digital pin as output:
43 pinMode(ledA, OUTPUT);
44 pinMode(ledB, OUTPUT);
49 // here is where you'd put code that needs to be running all the time.
51 // check to see if it's time to blink the LED; that is, if the
52 // difference between the current time and last time you blinked
53 // the LED is bigger than the interval at which you want to
55 unsigned long currentMillis = millis();
57 if(currentMillis - previousMillisA > intervalA) {
58 // save the last time you blinked the LED
59 previousMillisA = currentMillis;
61 // if the LED is off turn it on and vice-versa:
66 // set the LED with the ledState of the variable:
67 digitalWrite(ledA, ledStateA);
70 if(currentMillis - previousMillisB > intervalB) {
71 // save the last time you blinked the LED
72 previousMillisB = currentMillis;
74 // if the LED is off turn it on and vice-versa:
79 // set the LED with the ledState of the variable:
80 digitalWrite(ledB, ledStateB);
85 2. Inserire un secondo LED con intervallo 500ms
86 1. Trasformare il codice utilizzato in una State Machine