How to use BUTTON command right?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2005
    Location
    Denmark
    Posts
    31

    Question How to use BUTTON command right?

    Hi,

    I'm trying to switch a relay on and off with the help of BUTTON and TOGGLE command.

    It's working but not the way I want it to work, because when I press the button
    the relay is switching on and off like a old fasion doorbell.

    How do I make a "while button is pressed just toggle once and then wait to next
    time the button is pressed" before switching again?

    Gert
    *Let's do it*

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


    Did you find this post helpful? Yes | No

    Wink Eye in the sky ...

    Hi, Gert

    And what about showing us some of your lines ????

    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 " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Hi Gert,

    I think this is what you may be after:
    Code:
    ' ---------- [ I/O Definition ] ----------
    TRISC = %00000001       ' Set PORTC (0-2 input) rest Outputs
    PORTB = 0
    
    ' ---------- [ System Inputs ] ----------
    Switch      Var PORTC.0         ' Momentary Switch on PORTC.0
    
    
    ' ---------- [ System Outputs ] ----------
    RedLED      VAR PORTB.1     ' All LEDs connected
                                ' between RC pins and
                                ' ground via resistor
    
    Main:
        If Switch=1 Then                      ' If button is pressed:
            Toggle RedLED                     ' Toggle the LED
            loop: If Switch=1 Then Goto loop  ' Wait until the button is released
        Endif
    Goto Main
    Regards,

    Steve

  4. #4
    Join Date
    Nov 2005
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Try this

    Is this wht your after try it and lets us know
    it uses 1 button to turn led on/off

    led1_status var bit
    button1 var portb.0
    led1 var portb.1
    main:
    if button1 = 1 then ' if the button is pressed

    if led1_status = 1 then ' if its last state was 1

    led1_status = 0 ' make it 0
    low led1
    pause 500 'debounce

    else

    led1_status = 1 ' the last state was a 0 so now make it a 1
    high led1
    pause 500 'debounce

    endif

    endif


    chuck

  5. #5
    Join Date
    Nov 2005
    Posts
    51


    Did you find this post helpful? Yes | No

    Default opps!

    I see that i missed the goto main of at the end

    i see that Tissy replied beofre me that must have been while i went and add a coffie but at least you have got to ways of doing it now

    chuck

  6. #6
    Join Date
    Mar 2005
    Location
    Denmark
    Posts
    31


    Did you find this post helpful? Yes | No

    Smile Thanks

    Hi,

    Thanks to Tissy and Chuck for your examples.

    I can conclude that you don't use the BUTTON command when you "read" a switch.
    I just thought that it was possible to set up all the parameters with the BUTTON command.

    But I think that your examples teach me that using IF - THEN and GOTO or WHILE - WEND gives me much better possibilities.

    Gert
    *Let's do it*

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