This is my code. When I run it, the motor keeps spinning, but the sensor does not seem to read any values or might only read once. Additionally, it prevents my other code from running properly, as if it occupies the execution space of other code. How can I fix this issue?
void colorBlue(double speed) {
bool a=true;
while(a){
Optical4.gestureDisable();
Optical4.color();
if (Optical4.color() == blue) {
Brain.Screen.clearScreen();
Brain.Screen.print("Blue");
M5.spin(directionType::fwd, speed, pct);
M6.spin(directionType::fwd, speed, pct);
a=false;
} else if (Optical4.color() == red) {
Brain.Screen.clearScreen();
Brain.Screen.print("Red");
wait(140,msec);
M5.stop(brake);
M6.stop(brake);
wait(220,msec);
} else {
M5.spin(directionType::fwd, speed, pct);
M6.spin(directionType::fwd, speed, pct);
}
}
}