4 Un incrocio costituito da due strade, una principale e una secondaria.
5 La via viene concessa al secondario alla pressione di un bottone,
6 il secondario cambia automaticamente dopo una pausa.
7 Viene utilizzato un oggetto della libreria common per gestire i LED.
9 Uno stimolo esterno rappresentato dalla pressione di un bottone
10 causa il passaggio di stato.
12 Questo sketch usa due FSM indipendenti che modificano i rispettivi stati.
14 - Schema per un led RGB: https://lab.piffa.net/schemi/rgb.jpg
15 - Schema per un bottone: https://www.arduino.cc/en/uploads/Tutorial/inputPullupButton.png
19 const byte input = 2; // PIN del bottone
21 enum states_available { // Stati della FMS
22 turn_green, // Dinamico, transizione
29 states_available FSM1 ;
30 states_available FSM2 ;
34 pinMode(input, INPUT_PULLUP);
39 RGBLed led_main(11, 10, 9);
40 RGBLed led_secondary(8, 7, 6);
44 // Semaforo principale
47 FSM1 = green ; // Setta il prossimo state
48 FSM2 = red ; // Setta il prossimo state
57 if (digitalRead(input) == LOW) {
58 FSM1 = turn_red ; // Il passaggio di stato avviene alla pressione di un bottone
68 FSM2 = turn_green; // Stimolo al semafor secondario
78 // Semaforo Secondario
80 led_secondary.Green();
81 FSM2 = green ; // Setta il prossimo state
86 FSM2 = turn_red ; // Niente stimoli
90 led_secondary.Yellow();
101 Serial.print(millis());
102 Serial.print(" \t Stato attuale Main: ");
104 Serial.print(", secondary: ");
105 Serial.println(FSM2);