This Study Resource Was
This Study Resource Was
To prepare a traffic light system which can switch between five colour states depending on time
intervals. The states are, greenLeft, yellowLeft, green, yellow, and red. The system will stay on these
states for 15 seconds, 5 seconds, 40 seconds, 10 seconds, and 70 seconds respectively. The system will
always start on the greenLeft state. The system can be interrupted at any time and will either reset or
end afterwards. The wait time for the red state can also be lowered to 25 seconds if either a pedestrian
request-to-walk button is pressed or if there are at least 6 cars waiting at the intersection.
1. Declare, prevState, interval, timer, cars, walk, interrupt = false, reduce = false
2. Set prevState to red
3. Set state based on prevState
a. state: greenLeft
m
er as
when prevState is red
co
eH w
set prevState to greenLeft
set light and arrow light to green
o.
rs e
set 15 sec to interval
ou urc
stay in this state for “interval” sec [see wait for interval - f]
go to #3
o
b. state: yellowLeft
when prevState is greenLeft
aC s
vi y re
stay in this state for “interval” sec [see wait for interval - f]
ar stu
go to #3
c. state: green
is
d. state: yellow
when prevState is green
This study source was downloaded by 100000805897387 from CourseHero.com on 09-26-2021 15:20:39 GMT -05:00
https://www.coursehero.com/file/66409588/pseudocode-w3docx/
set prevState to yellow
set light to yellow
set 10 sec to interval
stay in this state for “interval” sec [see wait for interval - f]
go to #3
e. state: red
when prevState is yellow
m
go to #3
er as
co
eH w
f. Wait for Interval
o.
i. Reset timer (0)
rs e
ii. If interrupt = true
ou urc
1. Yes (go to iii)
2. No (go to vi)
iii. Turn of the system?
o
2. No (go to v)
vi y re
Go to #3
ar stu
vi. If (car > 5 || walk = true) && (reduce = true && interval > 25)
1. Yes (go to vii)
2. No (go to viii)
vii. Set interval to 25 sec
is
This study source was downloaded by 100000805897387 from CourseHero.com on 09-26-2021 15:20:39 GMT -05:00
https://www.coursehero.com/file/66409588/pseudocode-w3docx/
Powered by TCPDF (www.tcpdf.org)