I apprecitate I just realized today that the sensor uses IR, so I will consider using some sort of border like the cardboard to protect it from other IR frequencies from reaching it. Today I figured out the problem with my code and it seems that I had to nest an if statement to compensate with the transition between a dark to bright color (black to white).
Code:
if ( light >= 1 && light <= 99 ) //interval of white (Bright)
{
light = getAnalogInput(1);
if (light > 99){
a = 1;
}
PrintToScreen ( "a: %d\n" , (int)a ) ;
PrintToScreen ( "Light: %d\n" , (int)light ) ;
}
if ( light > 99 ) //interval of black (Dark)
{
light = getAnalogInput(1);
if (light <= 1 && light <= 99){
b = 1 ;
}
}
if ( a == 1 || b == 1 )
{
value++ ;
a =0 ;
b = 0 ;
}
Now instead of counting RPM, I made so that a certain distance equals one count. Take for example that it takes 10 inches for one round of spins of the motor. If I want to go 20 inches all I would need to do is execute this process twice. I want to know if this idea is pratical to use. I plan on getting the correct measurements at competition.