/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./
/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.
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 }
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.