© Fort Street High School Robotics
To detect the silver strip, you will need to:
task main() {
// put variables here
int leftR, leftG, leftB;
int rightR, rightG, rightB;
while (1) {
// repeatedly get the sensor values
// repeatedly check the sensor values to see if it is silver
}
}
Code likes to run from top to bottom, but you want your code to either be detecting the silver strip OR performing the search.
The easiest way to do this is to set up a flag that tells the code which task we want to do. If the flag is 1, we do strip detection, if the flag is 2 we go forward, if the flag is 3, we are done.
task main() {
// put variables here
int leftR, leftG, leftB;
int rightR, rightG, rightB;
int currentTask = 1; // our 'task' flag
// 1: silver strip detection
// 2: going forward
// 3: idle/stop program
while (1) {
if (currentTask == 1) {
// repeatedly get the sensor values
// repeatedly check the sensor values to see if it is silver
if (silver) {
// beep and wait a second
currentTask = 2; // change task to 'go forward'
}
}
else if (currentTask == 2) {
// go forward
if (forward enough) {
currentTask = 3;
}
}
else if (currentTask == 3) {
// stop all motors, do nothing else
}
}
}