This example of digital output uses 3 LEDs to create a traffic light. It starts with the red, after 7 seconds becomes green, after 10 seconds becomes yellow and after 3 seconds it resumes with the red (see Figure 2 and Video 1). It can be managed from the Internet via start and stop commands.
Connect the 3 LEDs as shown in Figure 1:
The longest PIN is positive.
Write a sketch K to define:
red :: !d1, yellow :: d2, gnd :: d3, green :: d4start, stopgnd :: d3green :: d4red :: !d1yellow :: d2s=0start = [gnd=0, status=0, s=1]stop = [red=0, yellow=0, green=0, status=1, led=1, s=0]s==1 -> [red=1, yellow=0, green=0, s=2 ## 7]s==2 -> [red=0, yellow=0, green=1, s=3 ## 10]s==3 -> [red=0, yellow=1, green=0, s=1 ## 3]or simply load the sketch into the workspace with the command
] charge e03_traffic_lightThe start command contains status=0 to disable the status LED. The stop command contains status=1 to enable the status LED. Find out what happens if you don't use status=0.
Try the following commands now:
] startthe traffic light starts with the red, after 7 seconds becomes green, after 10 seconds becomes yellow and after 3 seconds it resumes with the red (see Video 1)
] pausethe traffic light stops
] playthe traffic light resumes
] stopturns off the traffic light
] ?--- Pin connectionsgnd :: d3 green :: d4 red :: !d1 yellow :: d2 --- Variabless = 0 --- Commandsstart = [gnd=0,status=0,s=1] stop = [red=0,yellow=0,green=0,status=1,led=1,s=0] --- Ruless==1 -> [red=1,yellow=0,green=0,s=2 ##7] s==2 -> [red=0,yellow=0,green=1,s=3 ##10] s==3 -> [red=0,yellow=1,green=0,s=1 ##3]shows the sketch in the workspace
] savestores on archive the sketch in workspace
] newerase the workspace
] ?nullshows the sketch in the workspace
] cat--- /smick.kgnd :: d3green :: d4red :: !d1yellow :: d2s = 0start=[gnd=0,status=0,s=1]stop=[red=0,yellow=0,green=0,status=1,led=1,s=0]s==1 -> [red=1,yellow=0,green=0,s=2 ##7]s==2 -> [red=0,yellow=0,green=1,s=3 ##10]s==3 -> [red=0,yellow=1,green=0,s=1 ##3]okshows the sketch stored on archive after the last save
] loadloads the sketch in the workspace
] ?Wath does it show?
In this lesson you learned: