Hello everyone, I'm new to robotics and i'm trying to write a line follower robot code using switch case
The problem comes with case statement. That is if i use 3 line sensors, i get 3 inputs. So how can i write switch case for different cases? Like.. case 101:
break;
case 110:
break;
Before going ahead, the code i have tried for testing:
int s[1]; //2 sensors
void setup()
{
pinMode(2, INPUT);
pinMode(12, INPUT);
pinMode(13, OUTPUT);
}
void loop()
{
s[0]= digitalRead(2);
s[1]= digitalRead(12);
switch (s[])
{
case {1,0}:
digitalWrite(13, LOW);//led connected to pin 13
break;
case {1,1}:
digitalWrite(13, HIGH);
break;
}
}
But it shows the error : expected primary expression before ']' token.
Looks like the switch statement doesn't take array.
Is there a way to do with switch case or it's not possible? How to combine all the inputs from sensors and put it in switch statement?
I hope i have expressed properly. Any help would be appreciated.
Sorry for my bad english