smaller mbed board traffic lights
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:60bfe7e2affd
diff -r 000000000000 -r 60bfe7e2affd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 07 14:40:48 2016 +0000 @@ -0,0 +1,82 @@ +#include "mbed.h" + +//Traffic Light Timing, sets a variable high when the light is Red +DigitalOut RED(p15); +DigitalOut GRED(p16); +DigitalOut AMBER(p17); +DigitalOut GAMBER(p18); +DigitalOut GREEN(p19); +DigitalOut GGREEN(p20); + +int flag; + +void stop(void) +{ flag = 1; + RED = 1; + GRED = 0; + AMBER = 0; + GAMBER = 0; + GREEN = 0; + GGREEN = 0; + wait(3); + } + + + +void hold(void) + { flag = 0; + int x; + for(x=0; x<3; x++) + { RED = 1; + GRED = 0; + AMBER = 0; + GAMBER = 0; + GREEN = 0; + GGREEN = 0; + wait(0.5); + RED = 1; + GRED = 0; + AMBER = 1; + GAMBER = 0; + GREEN = 0; + GGREEN = 0; + wait(0.5); + } + } + +void go(void) + { flag = 0; + RED = 0; + GRED = 0; + AMBER = 0; + GAMBER = 0; + GREEN = 1; + GGREEN = 0; + wait(3); + } + +void waiting(void) +{ flag = 0; + RED = 0; + GRED = 0; + AMBER = 1; + GAMBER = 0; + GREEN = 0; + GGREEN = 0; + wait(1.5f); + } + + +int main() { + while(1) + { + stop(); + hold(); + go(); + waiting(); + +} + +} + + \ No newline at end of file