How can I correct the switch/case statement to work fine ??
Thanks!
switch (volts > 150 || linesensor_left < kWhiteThreshold)
{
case 'linesensor_left < kWhiteThreshold':
go(50,-50);
delay(1500);
Serial.println("right linesensor touched");
case 'volts > 150':
go(200,200);
Serial.println("go forward ");
}
How can I correct the switch/case statement to work fine ??
You can't. A switch statement expects ONE variable as input - a single character, an int, etc. The value in the variable can have a any value. You then provide a case for each value.
case 'linesensor_left < kWhiteThreshold':
This is nonsense.
Ditch the switch statement. Use multiple ifs.
Get the syntax correct as a starting point:
if (volts>150){ condition = 1;}
if (linesensor_left < kWhiteThreshold){condition = 2;}
switch (condition){
case 1:
// code
break;
case 2:
// code
break;
}
Something like that? but how I declare condition?and where?
if (linesensor_left < kWhiteThreshold) {condition = 1;}
if (linesensor_right < kWhiteThreshold){condition = 2;}
if (volts > 150) {condition = 3;}
switch (condition){
case 1:
go(70,-70);
delay(1500);
Serial.println("senzor linie stanga atins");
break;
case 2:
go(-70,70);
delay(1500);
Serial.println("senzor linie dreapta atins");
break;
case 3:
go(200,200);
Serial.println("MERGI in fata");
break;
}
At the top of your sketch, before setup, add:
byte condition = 0;
While working in your IDE and assuming the code compiles, press Ctrl-T before you post your code. That formats the code to a standard C-style format and makes it easier for us to read.