Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --- ATTRIBUTES --- //
- int subStateMachineTraffic;
- boolean subStateMachineTrafficBusy = false; // Is the substateBusy?
- boolean canBeChangedSubTraffic;
- const int TRAFFIC_OPEN = 0;
- const int TRAFFIC_CLOSING = 1;
- const int TRAFFIC_CLOSED = 2;
- const int INTERVAL_TRAFFIC_GREEN = 8000;
- const int INTERVAL_TRAFFIC_ORANGE = 3000;
- // --- SETUP --- //
- void subStateMachineTrafficSetup(int trafficLight) {
- subStateMachineTrafficBusy = true;
- canBeChangedSubTraffic = false;
- subStateMachineTraffic = TRAFFIC_OPEN;
- TRAFFIC_OPEN_entry(trafficLight);
- }
- // --- FUNCTIONS --- //
- void subStateMachineTrafficLoop(int trafficLight) {
- switch (subStateMachineTraffic) {
- case TRAFFIC_OPEN :
- TRAFFIC_OPEN_do();
- if (canBeChangedSubTraffic) {
- TRAFFIC_OPEN_exit();
- subStateMachineTraffic = TRAFFIC_CLOSING;
- TRAFFIC_CLOSING_entry(trafficLight);
- }
- break;
- case TRAFFIC_CLOSING :
- TRAFFIC_CLOSING_do();
- Serial.println("two");
- if (canBeChangedSubTraffic) {
- TRAFFIC_CLOSING_exit();
- subStateMachineTraffic = TRAFFIC_CLOSED;
- TRAFFIC_CLOSED_entry(trafficLight);
- }
- break;
- case TRAFFIC_CLOSED :
- TRAFFIC_CLOSED_do();
- Serial.println("three");
- if (canBeChangedSubTraffic) {
- TRAFFIC_CLOSED_exit();
- }
- break;
- }
- }
- // --- SETTERS --- //
- // --- ENTRY | DO | EXIT --- //
- // || -- TRAFFIC OPEN -- || //
- void TRAFFIC_OPEN_entry( int trafficLight) {
- turnTrafficLightOn(trafficLight, GREEN); // Changes traffic light to green
- }
- void TRAFFIC_OPEN_do() {
- buzzerTicking(SLOW); // Buzzer ticks slowly
- myfnUpdateDisplay(getStopSign()); // Displays a stop sign on the 7-segment display
- int currentMillis = 0;
- currentMillis = millis();
- if (currentMillis > INTERVAL_TRAFFIC_GREEN) {
- canBeChangedSubTraffic = true;
- }
- }
- void TRAFFIC_OPEN_exit() {
- canBeChangedSubTraffic = false;
- }
- // || -- TRAFFIC CLOSING -- || //
- void TRAFFIC_CLOSING_entry(int trafficLight) {
- turnTrafficLightOn(trafficLight, ORANGE); // Changes traffic light to orange
- }
- void TRAFFIC_CLOSING_do() {
- buzzerTicking(SLOW); // Buzzer ticks slowly
- myfnUpdateDisplay(getStopSign()); // Displays a stop sign on the 7-segment display
- int currentMillis = 0;
- currentMillis = millis();
- if (currentMillis > INTERVAL_TRAFFIC_ORANGE) {
- canBeChangedSubTraffic = true;
- }
- }
- void TRAFFIC_CLOSING_exit() {
- canBeChangedSubTraffic = false;
- }
- // || -- TRAFFIC CLOSED -- || //
- void TRAFFIC_CLOSED_entry(int trafficLight) {
- turnTrafficLightOn(trafficLight, RED); // Turns traffic light back to red
- }
- void TRAFFIC_CLOSED_do() {
- buzzerTicking(SLOW); // Buzzer ticks slowly
- }
- void TRAFFIC_CLOSED_exit() {
- Serial.println("DEAD TIMER");
- if (getDeadTimer()) {
- Serial.println("DEAD TIMER DONE");
- subStateMachineTrafficBusy = false;
- headStateMachineSetup();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement