toggle or count?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96

    Default toggle or count?

    Simple question...
    I have a TX module I am sending to an RX board.
    I simply want to push a button once to latch a Relay "ON", then push the same button again to turn the relay "OFF".
    Yes my modules are working fine... I just need help with this simple brain teaser.
    I was thinking of adding + 1 to a variable with a initial condition of zero... each time the button is pushed then divide it down to an even or odd number. If odd the relay stays high, if even the relay if off.

    Basically I am making a simple state machine. I should know this but have not messed with state logic in a while.

    Could I use toggle to do this more simply?
    Padawan-78

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Just increment a variable and only pay attention to the LSB of that variable...
    i.e.

    x = x + 1

    if x.0 = 0 then -the variable is an even number

    if x.0 = 1 then -the variable is an odd number

  3. #3
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Talking

    That makes perfect sence.
    Perhaps in 10 more years I will be ready to apply for work with Lock Head Martin and propel the next Mars vehicle to welll... Mars. Until then, I will press on and keep learning the basics. Thanks again!
    Padawan-78

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by earltyso View Post
    Perhaps in 10 more years I will be ready to apply for work with Lock Head Martin and propel the next Mars vehicle to welll... Mars.
    Looks like the boys (and girls) in Pasadena have pretty much got Mars handled for now...as of tonight anyways...
    Maybe you should shoot for something a wee bit farther out

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


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by earltyso View Post
    Simple question...

    I was thinking of adding + 1 to a variable with a initial condition of zero... each time the button is pushed then divide it down to an even or odd number. If odd the relay stays high, if even the relay if off.


    Could I use toggle to do this more simply?


    Hi, Martian

    You also have, using a single BIT :

    IF Condition_true then relay_state = relay_state ^ 1

    ...

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

Similar Threads

  1. Toggle command
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2011, 02:07
  2. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  3. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  4. TOGGLE code space and ICD
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th October 2006, 16:08
  5. Count command
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th September 2005, 19:04

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