Jake Beazley L6Ea Page of
Microcontroller Project
Aim: To program a PICAXE microcontroller to mimic a traffic light sequence, complete with pedestrian crossing lights (and trigger switch). This could be used to control a set of pedestrian lights.
Output Ports
Key: “Tr.” represents traffic, “Pe.” represents pedestrian.
For example, the denary number “31” would translate to the byte “00011101” and would then transfer to the eight outputs, so all connected outputs would be high (and therefore lit) apart from the amber light for traffic. The binary number represents one of two logic states – 0 or 1. The three most significant bits of these bytes can be ignored for this program as they are not used.
Circuit Operation
This circuit emulates a traffic light sequence.
- The “let pins = 9” command transfers the byte “00001001” to the 8 output pins, which lights the LEDs traffic green, and pedestrian red.
- The “wait 60” command makes the program wait 60 seconds before moving on to the next instruction. This is so after the program has run through, the pedestrians cannot cross again in quick succession, thus avoiding too much interruption to traffic flow.
- “pin0=1” decision has two outputs: “no” loops back to the top of the decision diamond, “yes” links to the rest of program. This checks if an input switch (a button for pedestrians) has been pressed.
- “wait 12” lets 12 seconds elapse until the next command, this means that the lights do not change the instant the pedestrian presses the switch.
- “let pins = 10” transfers the byte “00001010” to the outputs, which keeps the pedestrian red light on, but changes the traffic lights from red to amber.
- “wait 3” waits 3 seconds before executing the next instruction.
- “let pins = 12” transfers the byte “00001100” to the output pins, which again keeps the pedestrian red on, but changes the traffic light to red.
- “wait 1” waits one second before executing “let pins = 20”, this is for safety as the traffic lights should be red before the pedestrian light turns green. 20 is the denary number that represents “00010100”, which assigns the appropriate logic level to each of the 8 output pins – in this case traffic red and pedestrian green.
- “wait 8” allows 8 seconds for any pedestrians waiting to cross safely.
- “let b0 = 5” assigns the value of 5 to the variable b0 (one of thirteen variable spaces in the PICAXE's RAM, each capable of storing one byte).
- The “b0 = 0” decision diamond checks if the value stored in the register b0 is 0. If it is, then it carries on with the rest of the program, if not then the following occurs: