View Single Post
  #9   Spotlight this post!  
Unread 10-02-2005, 14:39
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
Re: One button wonder

Ask any of my students what my favorite question is and they'll answer "What is the definition of a button tap?". I grilled them with that question until they finally understood it. A button tap is when the button is currently pressed and it wasn't pressed the last time you looked at it. That's exactly what you want. You want to transition the relay only once per button press.

Code:
static char p1_sw_top_prev = 0;

// check if the button is pressed and last loop it wasn't pressed
if ((p1_sw_top == 1) && (p1_sw_top_prev == 0))
{
  // now transition your relay
  if (relay1.fwd == 1)
  {
    relay1.fwd = 0;
    relay1.rev = 1;
  }
  else
  {
    relay1.fwd = 1;
    relay1.rev = 0;
  }
}

p1_sw_top_prev = p1_sw_top;