Skip to content

Instantly share code, notes, and snippets.

@wise-introvert
Last active September 24, 2021 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wise-introvert/eaf57fcc0a4ec08c7c06e26ba6e783cd to your computer and use it in GitHub Desktop.
Save wise-introvert/eaf57fcc0a4ec08c7c06e26ba6e783cd to your computer and use it in GitHub Desktop.
START
SET "state" = "green"
SET "isAdvanceActive" = "true"
SET "timer" = 40 and begin auto-decrement
## Get current time
GET "timer" value
## Check if 4-light/5-states system is active
IF "isAdvanceActive" == "true"
## Check if the timer has reached 0
IF "timer" <= 0
## Update the state and reset the duration to appropriate values
IF "state" == "green"
SET "state" = "amber"
SET "timer" = 10
ELSE IF "state" == "amber"
SET "state" = "red"
SET "timer" = 210
ELSE IF "state" = "red"
SET "state" = "green-adv-left"
SET "timer" = 10
ELSE IF "state" = "green-adv-left"
SET "state" = "amber-adv-left"
SET "timer" = 5
ELSE
SET "state" to "green"
SET "timer" = 40
## Cars Sensor
Get number of cars from the cars-sensor
IF number of cars >= 6
IF "state" == "red" and "timer" > 25
SET "timer" = 25
## request-to-walk button
Check if the request-to-walk button was pressed
IF pressed
IF "state" == "red" and "timer" > 25
SET "timer" = 25
## interrupt
Check if an interruption to the system was detected
IF detected
OVERRIDE "state" and "timer" values
## Else block to handle 4-light/3-states system
ELSE
## Check if the timer has reached 0
IF "timer" <= 0
## Update the state and reset the duration to appropriate values
IF "state" == "green"
SET "state" = "amber"
SET "timer" = 10
ELSE IF "state" == "amber"
SET "state" = "red"
SET "timer" = 150
ELSE IF "state" = "red ELSE
SET "state" to "green"
SET "timer" = 40
## Cars Sensor
Get number of cars from the cars-sensor
IF number of cars >= 6
IF "state" == "red" and "timer" > 25
SET "timer" = 25
## request-to-walk button
Check if the request-to-walk button was pressed
IF pressed
IF "state" == "red" and "timer" > 25
SET "timer" = 25
## interrupt
Check if an interruption to the system was detected
IF detected
OVERRIDE "state" and "timer" values
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment