Question: I do not know how to structure my code to design a state machine in C. It requires the use of pigpio to the following
I do not know how to structure my code to design a state machine in C. It requires the use of pigpio to the following speciications.
The traffic light system should operate in the manner of a state machine. States: 1. Both N-S Red and E-W Red are lighted. All other LED off. Remain in this state 3 seconds. If override is not active, go to state 2. If override is active, go to state 9. 2. Both N-S Green and E-W Red are lighted. All other LED off. Remain in this state 7 seconds or until an override condition occurs whichever is shorter. If override is not active, go to state 3. If override is active, go to state 7. 3. Both N-S Yellow and E-W Red are lighted. All other LED off. Remain in this state 2 seconds. If override is not active, go to state 4. If override is active, go to state 9. 4. Both N-S Red and E-W Red are lighted. All other LED off. Remain in this state 3 seconds. If override is not active, go to state 5. If override is active, go to state 9. 5. Both N-S Red and E-W Green are lighted. All other LED off. Remain in this state 7 seconds or until an override condition occurs whichever is shorter. If override is not active, go to state 6. If override is active, go to state 8. 6. Both N-S Red and E-W Yellow are lighted. All other LED off. Remain in this state 2 seconds. If override is not active, go to state 1. If override is active, go to state 9. 7. Both N-S Yellow and E-W Red are lighted. All other LED off. Remain in this state 2 seconds. Go to state 9. 8. Both N-S Red and E-W Yellow are lighted. All other LED off. Remain in this state 2 seconds. Go to state 9. 9. Both N-S Red and E-W Red are lighted. Both N-S Blue and E-W Blue are lighted. All other LED off. Remain in this state a minimum of 10 seconds. Go to state 1. The traffic light system should operate in the manner of a state machine. States: 1. Both N-S Red and E-W Red are lighted. All other LED off. Remain in this state 3 seconds. If override is not active, go to state 2. If override is active, go to state 9. 2. Both N-S Green and E-W Red are lighted. All other LED off. Remain in this state 7 seconds or until an override condition occurs whichever is shorter. If override is not active, go to state 3. If override is active, go to state 7. 3. Both N-S Yellow and E-W Red are lighted. All other LED off. Remain in this state 2 seconds. If override is not active, go to state 4. If override is active, go to state 9. 4. Both N-S Red and E-W Red are lighted. All other LED off. Remain in this state 3 seconds. If override is not active, go to state 5. If override is active, go to state 9. 5. Both N-S Red and E-W Green are lighted. All other LED off. Remain in this state 7 seconds or until an override condition occurs whichever is shorter. If override is not active, go to state 6. If override is active, go to state 8. 6. Both N-S Red and E-W Yellow are lighted. All other LED off. Remain in this state 2 seconds. If override is not active, go to state 1. If override is active, go to state 9. 7. Both N-S Yellow and E-W Red are lighted. All other LED off. Remain in this state 2 seconds. Go to state 9. 8. Both N-S Red and E-W Yellow are lighted. All other LED off. Remain in this state 2 seconds. Go to state 9. 9. Both N-S Red and E-W Red are lighted. Both N-S Blue and E-W Blue are lighted. All other LED off. Remain in this state a minimum of 10 seconds. Go to state 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
