PDA

View Full Version : multi functions button press



malwww
- 18th May 2009, 10:38
i need help i wanna use 1 button to multi fonction things,ex. when i press the 1st time to swich led 1 in portb.0 2nd time swich led 2 in portb.1 so on or ,i use variables, this is my code but it doesnt work, if there another way please help

define osc 4

symbol led_1 = portb.0
symbol led_2 = portb.1
symbol led_3 = portb.2
button var porta.0
b0 var byte
portb = 0
porta.0 = 1
main:
count button,1000, b0
if button = 0 then
high led_1
pause 100
low led_1
if button = > 0 then
high led_2
pause 100
low led_2
if button = ??? then
high led_3
pause 100
low led_3
goto main

mister_e
- 18th May 2009, 17:30
Have you tried to read B0 variable instead?

Does it need to have a timeout? If so, probably not a bad idea to process COUNT only when you press on your push button.

malwww
- 20th May 2009, 04:06
hi mister_e im new in pbp i will try many ways and i hope someone here has a good ideas how it works ,thnks mister_e.

luminas
- 21st May 2009, 12:19
You should use temporary counter like this:

start:
button blabalabla... click
if a= 1 then blablabla
etc..
goto start:

click:
a=a+1
goto start

Chris Barron
- 21st May 2009, 23:22
i need help i wanna use 1 button to multi fonction things,ex. when i press the 1st time to swich led 1 in portb.0 2nd time swich led 2 in portb.1 so on or ,i use variables, this is my code but it doesnt work, if there another way please help

define osc 4

symbol led_1 = portb.0
symbol led_2 = portb.1
symbol led_3 = portb.2
button var porta.0
b0 var byte
portb = 0
porta.0 = 1
main:
count button,1000, b0
if button = 0 then
high led_1
pause 100
low led_1
if button = > 0 then
high led_2
pause 100
low led_2
if button = ??? then
high led_3
pause 100
low led_3
goto main


Don't you need some ENDIF statements through the code ?

GoldStar
- 23rd May 2009, 07:24
You should initialize B0 to be 0 and it's best to use Select Case for this code:


Select Case B0
Case 0:
high led_1
pause 100
low led_1
B0 = B0 + 1
Case 1:
high led_2
pause 100
low led_2
B0 = B0 + 1
Case Else
high led_3
pause 100
low led_3
B0 = 0
End Select

malwww
- 27th May 2009, 00:12
thank you GoldStar i will try it out and i post the result.