Single button function


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    The UI currently consists of one switch and an LCD. The switch is used to change time/date in normal mode. In the backdoor setup its used to set the time/date on a RTC.

    The advantage to having two switches is that the user could have autorepeat functionality when setting the clock in setup. The disadvantage is that the second switch would go unused the rest of the time, which is most of the time.
    Last edited by DynamoBen; - 7th June 2006 at 01:39.

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    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
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 09:10
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 03:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 23:43
  4. Pushbutton code routine suggestions?
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd September 2005, 02:02
  5. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 17:44

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts