Thread: One button to have two values.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by kim15 View Post
    How exactly do u do a key state events?

    Thanks
    The easiest way of doing this is with a switch statement

    Code:
    switch (state)
    {
      case 0:
        if (button_pressed)
        {
          count += (count < 100);
          if (count == 100)
          {
            count = 0;
            state = 1;
          }
          else if (count > 100)
          {
            count = 0;
          }
        }
        else
        {
          count = 0;
        }
    
        break;
    
      case 1:
        if (!button_pressed)
        {
          count += (count < 100);
          if (count == 100)
          {
            count = 0;
            state = 0;
          }
        }
        else
        {
          count = 0;
        }
    
        break;
        
    }
    Also noticed that I do not take the reading straight away -> I wait for 100 positive readings in a row before I change state.
    Last edited by Click_here; 12-19-2012 at 09:58 PM.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. write() and read() int values from socket returning wrong values.
    By Premjith P S in forum Linux Programming
    Replies: 8
    Last Post: 11-29-2012, 02:59 PM
  2. passing int values and *double values through message queues
    By Hyp3rTension in forum C Programming
    Replies: 11
    Last Post: 05-11-2012, 05:04 AM
  3. Replies: 100
    Last Post: 06-21-2010, 02:22 AM
  4. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  5. Scroll button values!
    By pran1 in forum Windows Programming
    Replies: 2
    Last Post: 03-30-2004, 09:35 AM