Thread: toggle switch
View Single Post
  #20   Spotlight this post!  
Unread 22-01-2006, 00:18
iBheat's Avatar
iBheat iBheat is offline
Registered User
FRC #0418 (Lasa Robotics)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Austin, TX
Posts: 24
iBheat is on a distinguished road
Re: toggle switch

If you are having problems with the OI reading multiple clicks with one click due to your reaction time being slower then one loop on the processor you can do this:
Code:
static unsigned int loops = 30;

if (p1_sw_trig && loops >= 30)
{
  relay1_fwd = !relay1_fwd;
  relay1_rev = !relay1_fwd;
  loops = 0;
}

if (loops < 30)
loops++;
Basically what this does is checks if the button is pushed every 30 processor cycles which with the default code is 786 ms (26.2 ms/Cycle * 30 Cycles). You can change the number from 30 to whatever you want!

Edit: Fixed a small bug

Last edited by iBheat : 22-01-2006 at 15:50.