Counting 2 Button Presses in order to toggle LEDs
mrdontay
Posts: 3
How would I adapt this code below to respond to the following events:
The assumption is that I have 2 buttons, let's say b1 and b2:
b1 pressed·1 time·and b2 pressed once = led blinks
b1 presssed·1 time·and b2 pressed twice =led blinks
b1 pressed two times and b2 pressed once = led blinks
and so on ......
Do I need two counters? if so, how do I do it?
I have been trying to adapt the code below to do what I want without success. Can someone please help a rookie. Thanks
counter VAR Byte
Main:
counter = 0
DO
DEBUG HOME
DEBUG ? counter
IF IN3 =1 THEN
counter = counter + 1
HIGH 15
PAUSE 500
LOW 15
PAUSE 500
ENDIF
LOOP UNTIL counter = 8
'At this point, counter will be 3
'So the IF counter=3 will ALWAYS be true
HIGH 13
PAUSE 1500
LOW 13
PAUSE 500
·
The assumption is that I have 2 buttons, let's say b1 and b2:
b1 pressed·1 time·and b2 pressed once = led blinks
b1 presssed·1 time·and b2 pressed twice =led blinks
b1 pressed two times and b2 pressed once = led blinks
and so on ......
Do I need two counters? if so, how do I do it?
I have been trying to adapt the code below to do what I want without success. Can someone please help a rookie. Thanks
counter VAR Byte
Main:
counter = 0
DO
DEBUG HOME
DEBUG ? counter
IF IN3 =1 THEN
counter = counter + 1
HIGH 15
PAUSE 500
LOW 15
PAUSE 500
ENDIF
LOOP UNTIL counter = 8
'At this point, counter will be 3
'So the IF counter=3 will ALWAYS be true
HIGH 13
PAUSE 1500
LOW 13
PAUSE 500
·
Comments
Button1 VAR Nib
Button2 VAR Nib
result VAR Byte
main:
DO WHILE IN4=0 AND IN5=0
LOOP
IF IN4=1 THEN
Button1=Button1+1
DEBUG ? Button1 ,CR
ELSEIF IN5=1 THEN
Button2=Button2+1
DEBUG ? Button2 ,CR
ENDIF
PAUSE 500
IF· Button1+Button2>2 THEN
result=Button1<<4
result=result+Button2
GOSUB decode
ENDIF
GOTO main
decode:
DEBUG ? result,CR
button1=0
button2=0
RETURN
Jeff T
Jeff T