Well, lets break it down a bit. And first off, I think what you really mean to ask is, “How do you create a loop with multiple requirments?” A variable is simple an int, unsigned char, char, signed char, etc. It hold the value of something. Like int NumberOne = 1; or you could say something like
int LimitSwitchValue = GetLimitSwitch(1, 1) //Not exact syntax but whenever you call LimitSwitchValue you will get the value returned by GetLimitSwitch(1, 1)
I have never used a line tracking sensor, but I think the code would look something like this.
unsigned int LineFollowerOne;
unsigned int LineFollowerTwo;
unsigned int LineFollowerThree;
while ( 1 )
LineFollowerOne = GetAnalogInput ( 1 ) ;
LineFollowerTwo = GetAnalogInput ( 2 ) ;
LineFollowerThree = GetAnalogInput ( 3 ) ;
if ( LineFollowerOne = LineFollowerTwo = LineFollowerThree = 1 ) // If they all return true
SetPWM ( 1 , 127 ) ; // STOP Right Side
SetPWM ( 2 , 127 ) ; // STOP Left Side
else if ( LineFollowerOne = LineFollowerTwo = LineFollowerThree = 0 ) // If they all return false
SetPWM ( 1 , 200 ) ; // Drive Right side rpighly 1/2 Speed Forward
SetPWM ( 2 , 200 ) ; // Drive Left side roughly 1/2 speed forward
This one is a little easier to explain. And has a little bit cooler example too.
Instead of using a single equals-sign in the test conditions of the loops and ifs, you need to remember to use a double-equals-sign.
The former makes an assignment. The latter compares.
PS: Some folks avoid making this mistake by putting their constants on the left side of the comparision, then if they forget an equals-sign, the preprocessor or compiler will catch the mistake because 1=x; is an invalid assignment.