This is cut & adapted from an old piece of graphical LCD menu / sub-menu code that I had laying about. There was more to it, but I removed some stuff that didn't apply. I *think* this code worked OK, but it's been a long time since I played with it. I added some comments to it...
Code:
; Button press pulls input pin LOW
; This next is placed with the subroutines...
CountButn: ; Count button press duration during a ~2s loop.
; Loop auto-exits after either 2 seconds, or when user releases the button
; (if released before 2 seconds are up).
; "HoldFlag" used to flag if button pressed (HoldFlag=0), or held (HoldFlag=1).
pause 50 : HoldFlag = 0 ; Pause to ignore switch bounce, clear flag
For CounterC = 0 to 49 ; 2s loop checks button input state...
Pause 40
if Butn then Exit_CountButn ; When button released, end loop
Next CounterC ; Increment counter each loop
Exit_CountButn: ; Test # loops button held for. If > 20 (0.8s), set 'HoldFlag'
if CounterC > 20 then HoldFlag = 1
Return
;
; ####################################
;
; Here we're in the "main menu" section and looking for a button press OR hold.
if Butn = 0 then ; On button press...
gosub CountButn ; check button press duration (press / hold)
WHILE Butn = 0 ; On return from sub, if button still held,
WEND ; wait until user releases button.
if HoldFlag then ; if HELD more than 0.8S, HoldFlag will be set
gosub PressPower : goto SecureChk ; Turn OFF, jump to security mode menu
EndIF
; if only pressed, NOT held, HoldFlag=0, so continue with whatever you need to do...
; Clear out previous arrow before drawing new...
CS_Left=0 : CS_Right=1 : GraphicFlag=1 : TextFlag=0
LoopStop=7 : StartADR=7690 ; graphic memory address
TempXY = PageFlag : gosub SetXY ; Set LCD X, Y locations
gosub Write_Data ; Write commands to LCD
PageFlag = PageFlag + 1 ; Increment page counter after button press
if PageFlag > 3 then PageFlag=1 ; Limits page counter to 1-3
gosub DrawArrow ; Draw new 8 byte arrow
CounterA = 74 ; After any press, loop continues 6sec looking for more presses.
EndIF
Bookmarks