View Single Post
  #2   Spotlight this post!  
Unread 25-02-2004, 13:14
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Button Programing

Put something this in your user_routine, substituting appropriately for switch_value and relay_fwd/rev:

Code:
static char relay_state = 0; /* 0 means forward, 1 means reverse */
static char last_switch_value = 1; /* will remember the last state of the switch */


if ((last_switch_value == 0) && (switch_value == 1))
{
    // here is where you toggle the relay state
    relay_state = 1-relay_state;
    if (relay_state == 0)
    {
        relay_fwd = 1;
        relay_rev = 0;
    }
    else
    {
        relay_fwd = 0;
        relay_rev = 1;
    }
}
last_switch_value = switch_value;