Are there alternatives to the counter method in wpilib? My team wants to count using an IR sensor every time a ball leaves the shooter. This would lead to a true or false value being returned. However, the counter method seems to only measure pulse lengths and duration, when we just want a variable to go up every time a ball leaves the shooter up to five. How would you do this?
I think a Counter is more for sensors than for detecting stuff like you want to. I would recommend doing this on your own. Something like this:
boolean wasDetected = false;
int counter = 0;
void periodic(){
boolean isDetected = // your logic for if there is a ball detected here
if(!isDetected && wasDetected){ // increment when ball leaves
counter++; // increment or maybe decrement depending on what you're trying to do
}
wasDetected = isDetected;
}
4 Likes
Thank you! This really helps a lot.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.