Button pressed time control


Results 1 to 13 of 13

Threaded View

  1. #10
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Lightbulb

    Hello Tanero

    Try this code:


    DEFINE OSC 4


    INIT :
    TRISA = 0
    TRISB = %10000000
    PORTA = 0
    PORTB = 0
    OPTION_REG.7 = 0
    INTCON = 0


    ButtonInput VAR PORTB.7
    Counter_A VAR BYTE
    LED_A VAR PORTB.0 : LED_A = 0
    PAUSE 750


    Waiting :
    COUNTER_A = 0
    PAUSE 250
    ' When you return form Check routine, following statement ensures that
    ' MCU doesn't go to debounce routine while you still pressing the button
    WHILE ButtonInput == 0 : WEND
    PAUSE 250
    ' Wait for button press
    WHILE ButtonInput == 1 : WEND


    Debounce :
    TOGGLE LED_A
    WHILE ButtonInput == 0 AND COUNTER_A =< 50
    COUNTER_A = COUNTER_A + 1
    PAUSE 100
    WEND


    ' Time over condition tested here, if 5 seconds elapsed, then output will
    ' change, if not 5 seconds passed, output will not change.

    Check :
    IF COUNTER_A == 50 THEN
    TOGGLE LED_A
    ENDIF
    GOTO Waiting


    END

    If 5 seconds don't elapse, output will still high "You didn't mention what will happen if 5 seconds don't pass, so I assumed you don't want to change the output", if 5 seconds pass, this will change the output to low, even if you still pressing the button after those 5 seconds, the output will not change.

    I think this shall work for you.
    Last edited by crematory; - 14th August 2005 at 22:40.

Similar Threads

  1. 8x8 keypad matrix...
    By mbox in forum General
    Replies: 5
    Last Post: - 9th October 2014, 18:43
  2. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  3. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

Members who have read this thread : 1

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