rbwilliams
New Member
Hello,
I am new to PICAXE. I am trying to create a Traffic Light with the 08M. It power up in "auto mode" (changing lights over time), at the same time is scanning inputs for a button press (pseudo-interrupt) that takes it out of "auto-mode" and goes into "manual mode" where the button press causes its corresponding output to stay lit, until another button is pressed. Resetting 08M puts it back into "auto-mode".
This is my code so far:
The stack overruns because I have too many nested loops. Any ideas about how I should change the code? Any suggestions as to how I show code in a message?
Thanks,
Roger
I am new to PICAXE. I am trying to create a Traffic Light with the 08M. It power up in "auto mode" (changing lights over time), at the same time is scanning inputs for a button press (pseudo-interrupt) that takes it out of "auto-mode" and goes into "manual mode" where the button press causes its corresponding output to stay lit, until another button is pressed. Resetting 08M puts it back into "auto-mode".
This is my code so far:
Code:
init:
let dirs=%0000111
main:
let pins = %00000001
gosub chkbuttons_loop
let pins = %00000010
gosub chkbuttons_loop
let pins = %00000100
gosub chkbuttons_loop
goto main
chkbuttons_loop:
for b1 = 1 to 10
gosub chkred
gosub chkyellow
gosub chkgreen
next b1
chkred:
if pin3 = 1 and pin4=0 then goto lightred
pause 100
return
chkyellow:
if pin3=1 and pin4 = 1 then goto lightyellow
pause 100
return
chkgreen:
if pin4=1 and pin3=0 then goto lightgreen
pause 10
return
lightred:
pause 200
if pin3 = 1 and pin4=0 then goto RED
goto chkyellow
lightyellow:
pause 200
if pin3=1 and pin4=1 then goto YELLOW
goto chkgreen
lightgreen:
pause 200
if pin4=1 and pin3=0 then goto GREEN
goto chkred
RED:
High 0
Low 1
low 2
goto chkbuttons2
YELLOW:
Low 0
High 1
Low 2
goto chkbuttons2
GREEN:
Low 0
Low 1
High 2
goto chkbuttons2
chkbuttons2:
do
gosub chkred
gosub chkyellow
gosub chkgreen
loop
Thanks,
Roger
Attachments
-
1.1 KB Views: 10
Last edited: