will this work for dedecting a held button?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Okay. I will need to think on this one. At lot of complex stuff happening compared to my little example. I wanted to take baby steps!

    Bart

  2. #2
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  2. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06

Members who have read this thread : 0

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