Traffic lights
tempest
Posts: 10
Use six LEDs; two red, two yellow and two green to create the lights at a traffic intersection. One set of lights will handle the North-South traffic while the other set will handle the East-West traffic. The LEDs will be arranged in the following typical traffic light form:
·
··········· ·· North-South Lanes ··········· East-West Lanes
·
······························································································· Red lights = 5 seconds
······························································································· Yellow lights = 1 seconds
······························································································· Green Lights = 4 seconds
·
·
Connect the LEDs to any Stamp pins that you wish and program the Stamp to light the LEDs in the proper sequence on a continuous basis using the times outlined above.· Show the working system to your instructor to obtain a grade of B for this module.
ok heres my code so far..it kinda works..but not really does anyone have any ideas on whats wrong or a different way I can go with this· code?
OUTPUT 10
OUTPUT 11
OUTPUT 12
OUTPUT 13
OUTPUT 14
OUTPUT 15
repeat:
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 10: PAUSE 500: HIGH 15: PAUSE 400
HIGH 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 14: PAUSE 100: HIGH 15: PAUSE 400
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 11: PAUSE 400: HIGH 13: PAUSE 500
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH· 12: PAUSE 100:
GOTO repeat
·
··········· ·· North-South Lanes ··········· East-West Lanes
·
······························································································· Red lights = 5 seconds
······························································································· Yellow lights = 1 seconds
······························································································· Green Lights = 4 seconds
·
·
Connect the LEDs to any Stamp pins that you wish and program the Stamp to light the LEDs in the proper sequence on a continuous basis using the times outlined above.· Show the working system to your instructor to obtain a grade of B for this module.
ok heres my code so far..it kinda works..but not really does anyone have any ideas on whats wrong or a different way I can go with this· code?
OUTPUT 10
OUTPUT 11
OUTPUT 12
OUTPUT 13
OUTPUT 14
OUTPUT 15
repeat:
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 10: PAUSE 500: HIGH 15: PAUSE 400
HIGH 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 14: PAUSE 100: HIGH 15: PAUSE 400
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH 11: PAUSE 400: HIGH 13: PAUSE 500
LOW 10: LOW 11: LOW 12: LOW 13: LOW 14: LOW 15
HIGH· 12: PAUSE 100:
GOTO repeat
Comments
If a left turn lane is added to the basic traffic light operation, just before the green light for straight through traffic would come on the left turn light must flash on and off at a .2 second rate while the red light stayed on. But if no car is currently waiting in the left-turn lane there would be no need for the left turn light to flash at all.
Notice that I've given the pins names -- makes reading the code a whole bunch easier, doesn't it?· At the top of your program, you would have something like this:
As it stands, one has to "decode" your program to figure out what's going on -- not good (especially when your teacher wants an explanation).· In the Help file you find a section called "The Elements of PBASIC Programming."· Let me suggest that following this style guideline will probably bump your grade a bit.· It's one thing to write a program that works, it's another to write a program that a fellow programmer (or your teacher) can immediately read and understand -- that means that YOU understand the program and it is expandible and maintainable.· Save criptic code for your C-language programs.
In the Help file you find that LOW and HIGH set a pin's output direction, so all your OUTPUT statements are redundant and a waste of code space.
The PIN definition will let you scan pins as an input, and this is what you'll need to move on.· Once you can read an input (lots of details on that in our "What's A Microcontroller?" book) you can apply some IF-THEN logic to handle the left-turn lane sequencing.
Have fun!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
HIGH 15 ' turn on the red light
when
RedLight = IsOn
is so much easier to type and understand?....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
The BS2 has a 'PAUSE mSecs' command. So you can say "PAUSE 5000" to pause 5000 mSecs, or 5 seconds.
It might be good to have a 'Pause1Sec' subroutine, so you can track the various lights, and change them when needed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office