Steve -
Okay, after quite a bit of study here this is my take on your idea. Just to recap, the project is to work like this:
User has four buttons
Pressing a button produced a beep
Continue to hold the button produces 2 beeps and the program jumps to appropriate routine.
I've added an error in the event someone tries to press multiple combinations.
I have a question about MCLR. You say that you assume it is disabled. I actually was wanting it enabled with the 4.7K resistor to the positive side. Does this create a problem while looking at that portb?
Does this show some level of what you gave as an example and my opinion of it?
Bart
Code:
getbutton var byte
storebutton var byte
delay var byte
timeout con 8 ' adjust this value to set length of time to hold down button
Start:
pause 15 ' sandwich the button read between a couple pauses for debounce
getbutton = GPIO & %00110101 ' get port values and keep only ports 0,2,4,5
pause 15
if getbutton = 0 then start ' sit and rotate if nothing pressed
gosub beep ' jump and make a noise if button is pressed
storebutton = get button ' keep a copy of which button was pressed
delay = 0
while delay < timeout ' wait to see if button is being held down
pause 15 ' sandwich the button read between a couple pauses for debounce
getbutton = GPIO & %00110101 ' get port values again and keep only ports 0,2,4,5
pause 15
if getbutton <> storebutton then start ' bail out if user releases button too soon or switches buttons
delay = delay + 1
wend
gosub beep ' jump and make two beeps to acknowledge button was held down
pause 20
gosub beep
' push and hold button section. Jump to appropriate button
select case storebutton
case %00000001
goto button0
case %00000100
goto button2
case %00010000
goto button4
case %00100000
goto button5
end select
goto error ' jump to an error routine if someone did something unexpected
like hold two buttons for example
Bookmarks