4 Version: singolo semaforo + millis + memoria giallo
6 Un singolo semaforo costruito col paradigma delle macchine a stato.
7 Viene utilizzato un oggetto della libreria common per gestire il LED.
9 Uno stimolo esterno rappresentato dalla pressione di un bottone
10 causa il passaggio di stato.
11 Il semaforo resta verde fino a quando non riceve lo stimolo
12 (es passaggio pedonale).
14 Implementata con millis() invece che con delay(),
19 const byte input = 2; // PIN del bottone
22 boolean wait = 0; // Memoria bottone
24 enum states_available { // Stati della FMS
30 states_available state ;
34 pinMode(input, INPUT_PULLUP);
39 RGBLed led(11, 10, 9);
46 if (wait && (millis() - timer >= pausa * 2/3)) {
51 if (digitalRead(input) == LOW) {
59 if (millis() - timer >= pausa /3) {
68 if (millis() - timer >= pausa) {
74 default: // In caso di default si fa giallo lampeggiante
84 Serial.print(millis());
85 Serial.print(" \t Stato attuale ");
87 Serial.print(" \t Wait: ");
93 1. Introdurre un secondo semaforo che cambia stato quando viene attivato
95 2. L'uso di delay() puo' essere limitativo: come rimediare?
107 2. Si potrebbe utilizzare un interrupt per gli stimoli oppure millis()
108 per gestire le pause.