Difference between revisions of "Traffic Light 1-Way"

From Flowcode Help
Jump to: navigation, search
Line 66: Line 66:
  
 
A full listing of the macros and properties available in this component are available from the [[Component:_ID_0c6b22fc_6e81_4406_aabd_5feb928e6aee|Components Section]].
 
A full listing of the macros and properties available in this component are available from the [[Component:_ID_0c6b22fc_6e81_4406_aabd_5feb928e6aee|Components Section]].
 +
 +
{{Fcfile2|TrafficLight1-WayWorksheet1.fcfx|Traffic Light 1-Way - Worksheet 1}}

Revision as of 12:05, 1 October 2019

Traffic lights are essential in modern road networks to help control and maintain the flow of traffic.

The lights must be clear to read and follow a regular pattern to allow motorists and other road users to know without any chance of confusion what the lights mean and what will come next in the sequence.

TL1.jpg


Contents

Exercise 1

Setup and analyse the light patterns of a traffic light.


Tasks

  • Create a new flowchart, and select ‘No chip’ as the target device. We choose no chip as this is a simulation only exercise.
  • Add the ‘Traffic Light 1-Way’ component to the 3D Panel, from the ’Simulation -> Scenarios’ category.
  • Adjust the 3D Panel so that you can see the traffic light, The Preset Views button or clicking the arrows at the top left of the 3D Panel window can be very helpful.
  • Add a component macro ‘AutomaticMode’ to start the lights moving through its pre-programmed light patterns.
  • Add a loop to your program to loop forever until the simulation stop button is pressed.
  • Run the simulation by clicking the Play button on the top toolbar.
  • Take note of the different states the lights can be in.


Working Example

Below you will see a working example to monitor the light sequence of a simple 1-way traffic light.

FC6 Icon.png Traffic Light 1-Way - Worksheet 1

TL2.jpg


Exercise 2

Recreate the automatic light sequence by directly controlling the states of each of the indicators on the traffic light.


Tasks

  • Open the flowchart from Ex1 and continue working from there.
  • Remove the component macro call to the AutomaticMode function to disable this from running.
  • Add component macro calls in your loop to call the SetLights component macro, add one for each state.
  • Add delay icons between the component macros to recreate the automatic mode flow and transition timings.


Exercise 3

Recreate the automatic light sequence using the pre-programmed light states.


Tasks

  • Open the flowchart from Ex1 and continue working from there.
  • Remove the component macro call to the AutomaticMode function to disable this from running.
  • Add component macro calls in your loop to call the SetLightState component macro, add one for each state.
  • Add delay icons between the component macros to recreate the automatic mode flow and transition timings.
  • Can you think of reasons why this way of coding is better or worse than in Exercise 2?


What to do next

Add a call to the GetStopGo function and assign the return value to a LED to indicate if it is safe to go through the light or not.


Component Details

A full listing of the macros and properties available in this component are available from the Components Section.

FC6 Icon.png Traffic Light 1-Way - Worksheet 1

Personal tools