We tried to use a vex sensor onto our FRC robot to be used to count revolutions by counting a series of alternating black and white tape on a motor. However there is something wrong with my code.
Code:
#include "Main.h"
void Autonomous ( void )
{
int c = 1;
unsigned char light;
int a = 0;
int b = 0;
int value = 0;
while ( value <= 5 ) //the transition of White to Black five times
{
SetPWM ( 10 , 190 ) ; //
SetPWM ( 11 , 190 ) ;
light = GetAnalogInput ( 1 ) ;
if ( light >= 0 && light <= 99 ) //interval of white (Bright)
{
a = 1 ;
PrintToScreen ( "a: %d\n" , (int)a ) ;
PrintToScreen ( "Light: %d\n" , (int)light ) ;
}
if ( light > 99 ) //interval of black (Dark)
{
b = 1 ;
}
if ( a == 1 && b == 1 )
{
value++ ; //problem starts here
a =0 ;
b = 0 ;
}
}
SetPWM ( 10 , 127 ) ;
SetPWM ( 11 , 127 ) ;
}
At the incremental of the variable value the RC begins to count continously up to five at the first instance and then it stops. I want it to only increment the variable value one at a time so that I can see a smooth transition. I started to believe that the vex light sensor is not capable to be used for FRC. Anyone know the problem or should I just use at gear tooth sensor. I appreciate the response.