View Single Post
  #3   Spotlight this post!  
Unread 25-02-2004, 15:53
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Button Programing

Quote:
Originally Posted by Alan Anderson
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;
Can't you do:
Code:
//...
//Init Relays
relay1_fwd = 1;
relay1_rev = 0;
//...
if (OI_Switch)
{
 relay1_fwd = !relay1_fwd;
 relay1_rev = !relay1_rev;
}
Just be sure to only do it again after a certain time. 26.2 ms is still fast, 38 hz fast.