Long / short press button...but reading ADC


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    Yes, I NEED to use ADC instead "usual" button(s).

  2. #2
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    just my two cents ..
    remove the Quartz and capacitors
    an use the internal oscillator if you don't need a precison time ..
    I love to use those small 12F675 ..
    Take care at programmation time you have datas (2 bytes) at the end of the eprom.
    read it before programming
    Francois

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    I have used 'for loop' to test for switch press duration as such....you would use your adc reading instead of GPIO check

    Code:
    if GPIO.1= 1 then start	       ' gpio is 1 for no press, 0 for pressed....or do 1 adc read and check ..about 100 microseconds
    
    FOR B5= 1 TO 100        '1 SECOND FOR TIMER
     PAUSE 10
     if GPIO.1= 1 then start	'or do 1 adc read and check ..about 100 microseconds
     NEXT B5
     
     '''' switch still pressed ...continue to 2 second press check
     
     FOR B5 = 1 TO 100       '2 SECONDS FOR 6 HR
     PAUSE 10
     if GPIO.1=1 then TIMER     'press is greater than 1 second in this loop... up to 2 second
     NEXT B5
      
    continuing here if switch still pressed !!!!

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    Thank you all for the support !

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    Code from Mr.Richard (Thanks !), see post #3, works just fine.
    But now I'm stuck again ...
    For accurate reading of ADC I use bubble-sort algoritm, how it's presented on this forum.
    Code:
    Main: 
    nr=1	
    for nr = 1 to 2
    For CounterA=0 to 8
    ADCON0 = %10000001
    		Pauseus 50			' Wait for channel to setup
    	        ADCON0.1 = 1			' Start conversion
    		While ADCON0.1=1:Wend		' Wait for conversion
    		DataW.HighByte=ADRESH		' Read variable from ADC and save
    		DataW.LowByte=ADRESL
    		RawData(CounterA)=DataW
    Next CounterA
    CounterA=0 
    Gosub Getsort
    next nr
    if adca=adcb then gosub efectuez		
    goto main
    
    
                             
    ;============================================================================
    GetSort:
    	If RawData(CounterA+1) < RawData(CounterA) then
    		DataW=RawData(CounterA)
    		RawData(CounterA)=RawData(CounterA+1)
    		RawData(CounterA+1)=DataW
    		If CounterA>0 then CounterA=CounterA-2
    		endif
    	CounterA=CounterA+1
    	If CounterA<9 then goto GetSort
    
    
    	DataW=0
    	For CounterA=3 to 6 
    		DataW=DataW+RawData(CounterA)
    		Next CounterA
    	ADCValue=DataW>>2
    if nr = 1 then 
    adca = adcvalue
    else
    adcb = adcvalue		
    endif
    Return
    ;============================================================================
    The code works amazing, almost no error ... for different value of ADC, I can do different tasks.
    BUT ... I can not figure out how to use the procedure of short/long press in this code... since even a short press makes the code to jump to "efectuez" (where I have different commands defined).
    I tried to use the same procedure as in post #3 ; I tried to put it into different places of the code, but without result ! Whatever I do, it's like pressing the button for a short time.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    can you explain what you are trying to achieve , and maybe another schematic .
    at this stage I can't see how an array sorting routine is useful for detecting button presses long or short .
    post the code for what have you tried

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Long / short press button...but reading ADC

    In the schematic posted in #1, R4 have different values ... for different commands.
    The code above is for reading accurate ADC ; works very, very fine.
    Tried to read short/long press of button ... but no succes. No matter what I do, I always have same result, as pressed "short".
    Sorry for my poor english, I use g...translate for many words.

Similar Threads

  1. Replies: 5
    Last Post: - 26th February 2011, 05:51
  2. Button press or not
    By lerameur in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th November 2010, 20:37
  3. 4 Bytes one button press
    By Dennis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th January 2010, 22:36
  4. Sleep until button press?
    By kevj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th October 2007, 03:47
  5. Button press and press & hold how to ?
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd August 2007, 03:37

Members who have read this thread : 3

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