Got the momentary digital switch working with the PICAXE 08m microprocesser. The switch required some resistance so that it didn’t continually send an ON signal to the PICAXE. It was a pain because I didn’t have a single large enough resistor to use, so I had to use a resistor chip and run it through several of the pins for a similar effect. This was enough to make the digital switch work just fine. Some things I learned this evening:
- When code is in SLEEP, WAIT or PAUSE mode, you can’t upload a new program to the chip.
- Using a momentary switch as an On/Off switch by setting variables is difficult.
Example Code:
b1 = 1
main:
if pin3=1 then
if b1=1 then
b1 = 2
else
b1 = 1
end if
end if
if b1 = 2 then
sound 4,(120,500)
end if
goto main
‘ ————————————————————————-
The problem with this script is that the button can be pressed at any time in the code; so if the button is pressed any time after it checks pin3 in the third line of code, it doesn’t actually register as a press. It has to be pressed at just the right time. The other issue is that if you press the switch for any length of time, the b1 variable might have a chance to be set several times; so by the time you let go of the switch, you have a 50% chance of the value actually being what it should be. — I’m not sure how to get around these issues without having an actual On/Off switch, instead of a momentary one. Circuit photo below….



