-/* Blink without Delay
+/* Blink without Delay - due led
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
+ modified by eaman
This example code is in the public domain.
// constants won't change. Used here to
// set pin numbers:
-const int ledA = 13; // the number of the LED pin
-int ledB = 12; //Secondo LED
+const int ledA = 13; // Primo LED
+const int ledB = 12; // Secondo LED
-// Variables will change:
+// Variabbili di stato
int ledStateA = LOW; // ledState used to set the LED
int ledStateB = LOW; // ledState used to set the LED
-
+
long previousMillisA = 0; // will store last time LED was updated
long previousMillisB = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long intervalA = 1000; // interval at which to blink (milliseconds)
-long intervalB = 500; // interval at which to blink (milliseconds)
+long intervalB = 500; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
void loop()
{
- // here is where you'd put code that needs to be running all the time.
-
- // check to see if it's time to blink the LED; that is, if the
- // difference between the current time and last time you blinked
- // the LED is bigger than the interval at which you want to
- // blink the LED.
- unsigned long currentMillis = millis();
-
- if(currentMillis - previousMillisA > intervalA) {
+// Primo LED
+ if (millis() > previousMillisA + intervalA) {
// save the last time you blinked the LED
- previousMillisA = currentMillis;
+ previousMillisA = millis();
// if the LED is off turn it on and vice-versa:
if (ledStateA == LOW)
digitalWrite(ledA, ledStateA);
}
- if(currentMillis - previousMillisB > intervalB) {
+// Secondo LED
+ if (millis() > previousMillisB + intervalB) {
// save the last time you blinked the LED
- previousMillisB = currentMillis;
+ previousMillisB = millis();
// if the LED is off turn it on and vice-versa:
if (ledStateB == LOW)
}
/* Domande
- 2. Inserire un secondo LED con intervallo 500ms
- 1. Trasformare il codice utilizzato in una State Machine
-
+ 1. Provare a isolare il codice per accendere ogni singolo led in una funzione:
+ - Quali variabili determinano il comportamento del LED?
+ - Come cambiano durante il corso dello script?
+ - Sono globali o locali?
+ - Quali parti vanno eseguite una sola volta e quali a ogni esecuzione?
*/