one button-two operations


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default one button-two operations

    I have a button and I want when I push it to go to labelone and when push again it to go to labeltwo , and so on.
    Last edited by savnik; - 15th July 2006 at 22:06.

  2. #2
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Just use a routine that sets a counter and then resets the next time. Branch depending on if the counter is 1 or 0. Put a time limit for the second if you want and have it reset at the expiration.

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BGreen
    Just use a routine that sets a counter and then resets the next time. Branch depending on if the counter is 1 or 0. Put a time limit for the second if you want and have it reset at the expiration.
    And how to make this;

  4. #4
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I would do it by interupting the pic and have an if statement:

    if c1 = 0 then
    do whatever
    resume (whatever your base routine is)
    do whatever else
    c1 = 0
    resume (whatever your base routine is)

    in your base routine you could put the pic to sleep for a defined period of time and if it had not been interupted within that time make c1 = 0. That way if it were 1 it would clear it.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    CounterA Var Byte
    CounterA=0
    Start:
        If PORTB.0=0 then 
            If CounterA<=1 then        
                CounterA=CounterA+1
                else 
                   CounterA=0
                endif
            endif
        While PORTB.0=0 : Wend : pause 50
        BRANCHL CounterA,[LabelOne,LabelTwo,LabelThree]
        '    
        ' stuf and other    
        '
        Goto Main
    
    LabelOne:
        ' Stuff 
        goto Main
    
    LabelTwo:
        ' Stuff 
        goto Main
    
    LabelThree:
        ' Stuff 
        goto Main
    The use of an internal Counter may reduce the code size too... look for RA4/T0CKI. Just read the TMR0 register and play with.
    Last edited by mister_e; - 16th July 2006 at 09:36.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    I have this code in my programm:

    LOOP:
    Button CH,0,255,0,b3,1,UHF 'b3 var BYTE
    Button CH,1,255,0,b3,1,VHF 'CH var PORTB.5
    PAUSE 100
    GoSub POSTING
    GoTo LOOP

    UHF:.................
    .................
    GoTo LOOP

    VHF:.................
    .................
    GoTo LOOP

    I want if push one time the button and release to go to UHF and if push again and release to go to VHF and if push again and release to go to UHF , and so on
    Last edited by savnik; - 16th July 2006 at 08:26.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    did you at least tried the previous?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    did you at least tried the previous?
    Yes , but not compile

    If PORTB.0=0 then ' ERROR Line 133: IF without a matching ENDIF. (TUNER.bas)
    If CounterA<=1 then
    CounterA=CounterA+1
    else
    CounterA=0

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Doh! corrected now.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Hi Savnik. Assuming you have your pushbutton on porta.0, you can toggle the variable "pushbutton" either 0 or 1 by making it a bit variable.

    PUSHBUTTON VAR BIT

    START:
    IF PORTA.0 = 1 THEN START
    IF PORTA.0 = 0 THEN LET PUSHBUTTON = PUSHBUTTON + 1
    GOSUB WAITFORRELEASE
    IF PUSHBUTTON = 0 THEN UHF
    IF PUSHBUTTON = 1 THEN VHF
    GOTO START

    WAITFORRELEASE:
    PAUSE 25
    IF PORTA.0 = 0 THEN WAITFORRELEASE
    RETURN

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question And with a little search ??? ...

    as title says ... you could find, between others, melanie's sweet words ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Thank you mister_e and peterdeco1.
    Both files are working

  13. #13


    Did you find this post helpful? Yes | No

    Talking

    Hello,

    I want to do the following thing, I have 2 pulsers one in rb0 and another one in rb1 and a LED in rb2 and rb3. I Need to on and off with the same pulser in rb0 the LED in rb2 and want to on and off with the same pulser in rb1 the LED in rb3.

    Since I can do it. Thanks







    Quote Originally Posted by mister_e
    Code:
    CounterA Var Byte
    CounterA=0
    Start:
        If PORTB.0=0 then 
            If CounterA<=1 then        
                CounterA=CounterA+1
                else 
                   CounterA=0
                endif
            endif
        While PORTB.0=0 : Wend : pause 50
        BRANCHL CounterA,[LabelOne,LabelTwo,LabelThree]
        '    
        ' stuf and other    
        '
        Goto Main
    
    LabelOne:
        ' Stuff 
        goto Main
    
    LabelTwo:
        ' Stuff 
        goto Main
    
    LabelThree:
        ' Stuff 
        goto Main
    The use of an internal Counter may reduce the code size too... look for RA4/T0CKI. Just read the TMR0 register and play with.

  14. #14


    Did you find this post helpful? Yes | No

    Talking

    Hello,

    I want to do the following thing, I have 2 pulsers one in rb0 and another one in rb1 and a LED in rb2 and rb3. I Need to on and off with the same pulser in rb0 the LED in rb2 and want to on and off with the same pulser in rb1 the LED in rb3.

    Since I can do it. Thanks



    Quote Originally Posted by savnik
    Thank you mister_e and peterdeco1.
    Both files are working

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. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06
  5. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 16:44

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