Hello all. I'm new to using picaxe microntrollers and looking to learn as much as I can about them to see what I can do with them. I have a strong background in electronics (13 years experience) but haven't done any programming since college back when I used assembly language and worked with the 68HC11 Motorola chips.
I can do small easy stuff no problems, but I would like to learn more complicated things. I've already built a simple single input, single output project for my kitchen and it works well.
What I'm trying to accomplish is to use a single button that can handle multiple output actions. So for instance, pressing once will do one thing, and pressing it again will do something else.
Here's the code I have now that I have been testing and it works well. But I'm not sure if it is an unorthodox or long way of doing what I want. If there is a simpler or less space wasting way of doing it, I'm all ears. I'm just looking to see if I'm on the right track or if I'm wasting precious space with unnecessary code.
What this basically does is perform an action, only once per button press. Changing the action each time it is pushed. It's designed to simulate a rising edge on the button (meaning holding button down does nothing).
What I would like to get myself to is timed actions. Say, push 3 times within a specified time and do action 3 or push 4 times within a specified time and do action 4. Are there timing functions available that I can use? I'm working with an 08M at the moment.
John
I can do small easy stuff no problems, but I would like to learn more complicated things. I've already built a simple single input, single output project for my kitchen and it works well.
What I'm trying to accomplish is to use a single button that can handle multiple output actions. So for instance, pressing once will do one thing, and pressing it again will do something else.
Here's the code I have now that I have been testing and it works well. But I'm not sure if it is an unorthodox or long way of doing what I want. If there is a simpler or less space wasting way of doing it, I'm all ears. I'm just looking to see if I'm on the right track or if I'm wasting precious space with unnecessary code.
Code:
init:
symbol led = 2 ;set led as an output on pin 2
symbol inp = pin3 ;set inp as an input on pin 3
b1 = 0 ;initialize led state variable
main:
if inp = 1 AND b1 = 0 Then ;checks if button is pushed and if led state is off
high led ;Turn on LED
sertxd("LED should be ON",13,10) ;Send message to computer
b1 = 1 ;Change led state to on
gosub btnheld
end if
if inp = 1 AND b1 = 1 Then ;checks if button is pushed and if led state is on
low led ;turn off led
sertxd("LED should be OFF",13,10) ;send message to comp
b1 = 0 ;Change led state of of
gosub btnheld
end if
goto main
btnheld:
do loop while inp = 1 ;Do nothing until button is released
pause 50 ;Small pause for debounce
return
What I would like to get myself to is timed actions. Say, push 3 times within a specified time and do action 3 or push 4 times within a specified time and do action 4. Are there timing functions available that I can use? I'm working with an 08M at the moment.
John