Hope this helps.
This code will need changing as it's in PBP, but the logic should still work with PB. I've used this to select options in a menu by pressing one button and then another to jump to the option selected, so in theory it could be used to select which program you run
Code:
LCDOUT $FE,2,"Main Menu"
lcdout $FE, $C0, "Select Option"
if Option = 1 THEN lcdout $FE, $D4, "Set Time and Date "
if option = 2 then lcdout $FE, $D4, "Set Night Period "
if option = 3 then lcdout $FE, $D4, "Set Normal Temps "
if option = 4 then lcdout $FE, $D4, "Run "
IF !H_butt THEN Option = option + 1 ; if button is low
pause 150
if option >4 then option = 0
If option = 1 Then ; if option =1 and S_but is taken low then reset LCD and gosub debounce followed by jump to option selected
If S_butt = 0 Then
LCDOUT $FE,1
Gosub SetButtonRelease
goto setup
endif
endif
If option = 2 Then
If S_butt = 0 Then
LCDOUT $FE,1
Gosub SetButtonRelease
goto nitetime
endif
endif
If option = 3 Then
If S_butt = 0 Then
LCDOUT $FE,1
Gosub SetButtonRelease
goto GetSetpoint
endif
endif
If option = 4 Then
If S_butt = 0 Then
LCDOUT $FE,1
Gosub SetButtonRelease
goto main
endif
endif
Goto mainmenu
The reason I use two buttons (one to select the option and one to confirm it) is that if you don't I found it hard to get passed the first option. For example, if you had
Code:
program1:
HIGH PORTB.1
PAUSE 500
LOW PORTB.1
PAUSE 500
GOTO program1
program2:
HIGH PORTB.2
PAUSE 500
LOW PORTB.2
PAUSE 500
GOTO program2
program3:
HIGH PORTB.3
PAUSE 500
LOW PORTB.3
PAUSE 500
GOTO program3
switch =0
if portB.0 = 0 then switch = switch +1
If switch = 1 then goto program 1
If switch = 2 then goto program 2
If switch = 3 then goto program 3
if switch >3 then switch=0
then as soon as you press your switch and the variable switch=1 it would jump to program 1 and never reach program 2 or 3.
Hope this helps, and sorry it's not converted into PB that you can use directly, but hopefully that won't be too hard to cchange
Bookmarks