Let's Make Robots!

expected ( before token ;

i am getting an error in the pinmode verify area that i dont know why im getting

 

here is my code

 

 

 

#define rightdc 5;
#define leftdc 4;
#define middleir A0;
#define leftir A1;
#define rightir A2;

int danger = 1000;

void setup()
{
 pinMode(rightdc, OUTPUT);
 pinMode(leftdc, OUTPUT);
}

void loop()
{
if (analogRead(middleir) < danger)
digitalWrite (right && leftdc, HIGH;

else if (analogRead(rightir) < danger)
digitalWrite (leftdc, HIGH);

else if (analogRead(leftir) < danger)
digitalWrite(rightdc, HIGH);

else if(analogRead(leftir && middleir) < danger)
digitalWrite(leftdc && rightdc, HIGH);

else if(analogRead(rightir && middleir) < danger)
digitalWrite(leftdc && rightdc, HIGH);

else if (analogRead(leftir && middleir && rightir) < danger)
digitalWrite (rightdc && leftdc, HIGH);

else if (analogRead(leftir && rightir) < danger)
digitalWrite(rightdc && leftdc, HIGH);

else (digitalWrite(leftdc, HIGH)
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

LoL, I just had the same problem again and I looked up the problem and got my own post, fixed now

left you with a trail to follow. :)

Good to know you were able to help yourself.

I could not help but notice that everyone is talking about bit shifting, but I can't seem to find an example of what your line should be. I think you are looking for:

variableOne = analogRead(some pin)
variableTwo = analogRead(some other pin)
if (variableOne < threshold && variableTwo < threshold) // if varOne is smaller AND varTwo is smaller as well, then...
{
  do something
}

if you want to do an "or" it would be: 
variableOne = analogRead(some pin)
variableTwo = analogRead(some other pin)
if (variableOne < threshold || variableTwo < threshold)  // if varOne is smaller  OR varTwo is smaller, then...
{
  do something
} 

/*Here is what you are asking for. I have removed all the errors in your code.
The semicolons on your defines are giving you the error in question. 
Once you remove those there are three other errors which are 
probably just typing mistakes on your part.
You left dc off the end of right in your if statement and in the last line 
your  brace before the digitalwrite needs removing and a 
semicolon placed at the end.*/



#define rightdc 5
#define leftdc 4
#define middleir A0
#define leftir A1
#define rightir A2

int danger = 1000;

void setup()
{
 pinMode(rightdc, OUTPUT);
 pinMode(leftdc, OUTPUT);
}

void loop()
{
if (analogRead(middleir) < danger)
digitalWrite (rightdc && leftdc, HIGH);

else if (analogRead(rightir) < danger)
digitalWrite (leftdc, HIGH);

else if (analogRead(leftir) < danger)
digitalWrite(rightdc, HIGH);

else if(analogRead(leftir && middleir) < danger)
digitalWrite(leftdc && rightdc, HIGH);

else if(analogRead(rightir && middleir) < danger)
digitalWrite(leftdc && rightdc, HIGH);

else if (analogRead(leftir && middleir && rightir) < danger)
digitalWrite (rightdc && leftdc, HIGH);

else if (analogRead(leftir && rightir) < danger)
digitalWrite(rightdc && leftdc, HIGH);

else digitalWrite(leftdc, HIGH);
}

/*At first error messages may be intimidating but they really are a big help 
and worth getting to understand. It makes for fast debugging when you can 
follow them*/

Merser did a good job, this code is now syntactically correct.

But the following statement:

digitalWrite (rightdc && leftdc, HIGH); 

does not do set both the rigthtdc and leftdc pins to high. In this case it only sets pin 5, because rightdc && leftdc means 5 && 4 which is 5. If you had other pins, let's say 3 and 4, you would have set pin 7, and nothing would happen to your motors, but you might have triggered something else. Think of how many hours you might have spent debbuging this :)

The same goes for analogRead(leftir && middleir && rightir). This is worse than trying to write to multiple pins because it makes no sense even if you could specify multiple pins the way you are. What do you mean by reading 3 pins at once? Do you want the average? The sum? The minimum? 

Then you go into all these if statements, half of which are not even reachable because their conditions would always be false (if I interpreted your "analogRead(leftir && rightir) < danger" correctly as "(analogRead(leftir) < danger) && (analogRead(rightir) < danger)" ).

Even if the logic had been correct the robot wouldn't work very well.

Heh thanks, I didn't look any further than fixing the code that was causing errors in the compiler. Whether the code will still do what he expects now wasn't my concern. Too many lessons at once can overwhelm.

5 && 4 ( && is LOGICAL and) is 1  : 5 = true, 4 =true, true && true =true = 1

5 & 4 ( & is BITWISE and) is 4: 5 (101) & 4(100) = 4(100)

similar with 3 && 4 = true, 3&4 = 0

bdk6 is right, I should be ashamed of myself, that is the logical AND operator which returns either 0 or 1

I made another mistake when I said 3 && 4 = 7. Even if I intrpreted && as &, 3 & 4 = 0.

This means the code will always try to read analog pin A1 and set the digital pin 1, which is also TX :)

A little tip do make it a little simple, could be improved:

 

 

#define RIGHTDC 5
#define LEFTDC 4
#define FW 18
#define L 19
#define R 20

void moveOn(char dir,long time){
   switch(dir){
      case 18: //we use numbers you can not use as pin in #defines
         digitalWrite(RIGHTDC, HIGH);
         digitalWrite(LEFTDC, HIGH);
         delay(time);
         digitalWrite(RIGHTDC, LOW);
         digitalWrite(LEFTDC, LOW);
         break;
      case 19:
         digitalWrite(RIGHTDC, HIGH);
         digitalWrite(LEFTDC, LOW);
         delay(time);
         digitalWrite(RIGHTDC, LOW);
         digitalWrite(LEFTDC, LOW);
         break;
      case 20:
         digitalWrite(RIGHTDC, LOW);
         digitalWrite(LEFTDC, HIGH);
         delay(time);
         digitalWrite(RIGHTDC, LOW);
         digitalWrite(LEFTDC, LOW);
         break;
   }
}
// call it as this: moveOn(FW, delaytime);}

void example(){
   long delaytime = 300;
   moveOn(FW, delaytime);
   //or 
   moveOn(L, 1200);
}

it is a simple function(could be totally improved), you can use it in your code :)

thankyou for the help but i am not yet a a skill level in which i understand what this does, i would like to take all sugestions into acount but i might just stick to my code for now as that is what i understand