case green:
led.Green();
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
state = wait_button ;
timer = millis();
}
case yellow :
led.Yellow();
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
state = turn_red ;
timer = millis();
}
case red :
led.Red();
- if (millis() > timer + pausa) {
+ if (millis() - timer >= pausa) {
state = turn_green ;
timer = millis();
}
break;
case green:
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer => pausa * 2/3) {
state = wait_button ;
timer = millis();
}
break;
case yellow :
- if (millis() > timer + pausa / 3) {
+ if (millis() - timer >= pausa / 3) {
state = turn_red ;
timer = millis();
}
break;
case red :
- if (millis() > timer + pausa /3) {
+ if (millis() - timer >= pausa /3) {
state = turn_sec_yellow ;
timer = millis();
}
break;
case sec_yellow :
- if (millis() > timer + pausa / 3) {
+ if (millis() - timer >= pausa / 3) {
state = turn_green ;
timer = millis();
}
break;
case green:
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
FSM1 = wait_button ;
timer = millis();
}
break;
case yellow :
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
FSM1 = turn_red ;
timer = millis();
}
break;
case green:
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
FSM2 = turn_yellow;
timer = millis();
}
break;
case yellow :
- if (millis() > timer + pausa / 3) {
+ if (millis() - timer >= pausa / 3) {
FSM2 = turn_red ;
timer = millis();
}
case green:
led.Green();
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
state = wait_button ;
timer = millis();
}
case yellow :
led.Yellow();
- if (millis() > timer + pausa * 2/3) {
+ if (millis() - timer >= pausa * 2/3) {
state = turn_red ;
timer = millis();
}
case red :
led.Red();
- if (millis() > timer + pausa) {
+ if (millis() - timer >= pausa) {
state = turn_green ;
timer = millis();
}
void loop() {
if (millis() - previousMillis >= interval) {
- previousMillis = millis();
+ previousMillis += interval ;
if ( i < sizeof(ledPins) - 1 ) {
// Spegni precedente led
else if (i == sizeof(ledPins) - 1 ) {
// Ultimo caso
i = 0;
- previousMillis = millis();
+ previousMillis += interval ;
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[ sizeof(ledPins) - 1 ], LOW);
}
void Update(long value) {
interval = value;
if (millis() - previousMillis >= interval) {
- previousMillis = millis();
+ previousMillis += interval;
if ( i < size - 1 ) {
// Spegni precedente led
else if (i == size - 1 ) {
// Ultimo caso
i = 0;
- previousMillis = millis();
+ previousMillis += interval;
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[ size - 1 ], LOW);
}
void Reverse(long value) {
interval = value;
if (millis() - previousMillis >= interval) {
- previousMillis = millis();
+ previousMillis += interval;
if (i == 0) { // Entry point, ultimo LED
digitalWrite(ledPins[size - 1], HIGH);
void UD(long value) {
interval = value;
if (millis() - previousMillis >= interval) {
- previousMillis = millis();
+ previousMillis += interval;
// Spegni precedente led
digitalWrite(ledPins[i], LOW);
i = i + inc ;
};
-
void setup() {
};
void loop() {
seq.UD(200);
};
-
-
-
--- /dev/null
+/*
+ Blink v1
+
+ Accensione e spegnimanto di un ledA utilizzando variabili
+ per impostare la velocita' del lampeggio.
+
+ */
+
+// Pin 13 ha un led collegato di default
+int ledA = 6;
+int ledB = 7;
+
+void setup() {
+ // Inizializziamo il PIN 13 come OUTPUT
+ pinMode(ledA, OUTPUT);
+ pinMode(ledB, OUTPUT);
+}
+
+void loop() {
+ // 1st step
+ digitalWrite(ledA, HIGH);
+ delay(150);
+ digitalWrite(ledA, LOW);
+ delay(50);
+ digitalWrite(ledB, HIGH);
+ delay(150);
+ digitalWrite(ledB, LOW);
+ delay(50);
+
+ // 2st step
+ digitalWrite(ledA, HIGH);
+ delay(150);
+ digitalWrite(ledA, LOW);
+ delay(50);
+
+
+ // 3st step
+ delay(150);
+ digitalWrite(ledA, LOW);
+ digitalWrite(ledB, LOW);
+ delay(50);
+ digitalWrite(ledA, HIGH);
+ digitalWrite(ledB, HIGH);
+ delay(350);
+ digitalWrite(ledA, LOW);
+ digitalWrite(ledB, LOW);
+ delay(50);
+
+
+ // Reverse
+ // 1st step
+ digitalWrite(ledB, HIGH);
+ delay(150);
+ digitalWrite(ledB, LOW);
+ delay(50);
+ digitalWrite(ledA, HIGH);
+ delay(150);
+ digitalWrite(ledA, LOW);
+ delay(50);
+
+ // 2st step
+ digitalWrite(ledB, HIGH);
+ delay(150);
+ digitalWrite(ledB, LOW);
+ delay(50);
+
+
+ // 3st step
+ delay(150);
+ digitalWrite(ledB, LOW);
+ digitalWrite(ledA, LOW);
+ delay(50);
+ digitalWrite(ledB, HIGH);
+ digitalWrite(ledA, HIGH);
+ delay(350);
+ digitalWrite(ledB, LOW);
+ digitalWrite(ledA, LOW);
+ delay(50);
+
+
+}
+