k_shirtcliffe
New Member
I'm new to picaxe and I'm just having a play around on a breadboard to get the hang of things but I have a question to which I am sure there is a very obvious answer!
I would like to know how to monitor an input continually - so I have attempted to create a simple program that will do the following:
Make an LED flash on and off when a switch is pressed. If the switch is pressed a second time it will switch the LED off and revert back to the beginning and start waiting for the switch to be pressed again...repeat.
The code I have attempted is as follows:
<code>
symbol pswitch=pin3
symbol led=4
symbol pressed=1
symbol notpressed=0
main:
if pswitch=pressed then goto flash
if pswitch=notpressed then goto main
flash:
high 4
wait 1
low 4
wait 1
if pswitch=pressed then goto ledoff
goto flash
ledoff:
low 4
goto main
</code>
My problem is that, in the flash loop, the program doesn't listen for an input until it has done the flash cycle. This is what I mean by "continually test an input" I would like the program to act upon a switch press no matter what point through the flash cycle the program has reached.
Also pressing the switch a second time doesn't actually acheive anything!
Thanks for your patience with what I'm sure is a stupid question!
Cheers,
Kev
I would like to know how to monitor an input continually - so I have attempted to create a simple program that will do the following:
Make an LED flash on and off when a switch is pressed. If the switch is pressed a second time it will switch the LED off and revert back to the beginning and start waiting for the switch to be pressed again...repeat.
The code I have attempted is as follows:
<code>
symbol pswitch=pin3
symbol led=4
symbol pressed=1
symbol notpressed=0
main:
if pswitch=pressed then goto flash
if pswitch=notpressed then goto main
flash:
high 4
wait 1
low 4
wait 1
if pswitch=pressed then goto ledoff
goto flash
ledoff:
low 4
goto main
</code>
My problem is that, in the flash loop, the program doesn't listen for an input until it has done the flash cycle. This is what I mean by "continually test an input" I would like the program to act upon a switch press no matter what point through the flash cycle the program has reached.
Also pressing the switch a second time doesn't actually acheive anything!
Thanks for your patience with what I'm sure is a stupid question!
Cheers,
Kev