Can someone debug this code please?

I keep getting different errors here the latest was were:

Arudino_Finale:74: error: expected primary-expression before 'bool'

Decision(bool checkRight,bool checkLeft);

^

Arudino_Finale:74: error: expected primary-expression before 'bool'

Decision(bool checkRight,bool checkLeft);

^

C:\Users\Hamza\Desktop\Arudino_Finale\Arudino_Finale.ino: At global scope:

Arudino_Finale:155: error: expected unqualified-id before 'if'

if (checkRight==false && checkLeft==true); /OBSATCLE ON LEFT, TURNING RIGHT/

^

Arudino_Finale:156: error: expected unqualified-id before '{' token

{

^

Arudino_Finale:160: error: expected unqualified-id before 'if'

if (checkRight==true && checkLeft==true); /NO OBSTACLE ON EITHER SIDE, TURN TOWARDS THE SIDE WITH MORE DISTANCE/

^

Arudino_Finale:161: error: expected unqualified-id before '{' token

{

^

Arudino_Finale:170: error: expected unqualified-id before 'if'

if (checkRight==false && checkLeft==false); /OBSTACLE ON BOTH SIDES, MOVE BACK, DRIFT/

^

Arudino_Finale:171: error: expected unqualified-id before '{' token

{

^

exit status 1
expected primary-expression before 'bool'

Arudino_Finale.ino (4.06 KB)

    Decision(bool checkRight, bool checkLeft);Start by taking the type declarations out of this function call. Compare how you are trying to call the Decision() function with how you call digitalWrite() for instance.

Just did, but now the error is : "no matching function for call to 'Decision(, )' "

Once you have problems with fixed code, post the new code.

One thing is that you have a mismatch between { and }. If you use tools -> autoformat in the IDE, you will find two } at the end of your code that start at the beginning of a line; that's one too many.

You can also see that because e.g.

if (checkRight == false && checkLeft == true); /*OBSATCLE ON LEFT, TURNING RIGHT*/

starts at the beginning of a new line; it should be indented.

This

int Decision(bool &checkRight, bool &checkLeft);

Does not match

int Decision(bool checkRight, bool checkLeft)

And why do you have a semi colon at the end of the if statements; e.g.

if (checkRight == false && checkLeft == true);

And in the checkRight function, you will never reach

  servo.write(115);

Thank You, I was able to remove all compile time errors. Thanks alot sterretje and UKHeliBob :slight_smile: :slight_smile: :slight_smile: :slight_smile:

However my car should turn when the ultrasonic sensors value for distance is equal to or lesser than zero but when i tested the code out, my car just went up and rammed in to the obstacle i.e door in this case. My ultrasonic also returns somwhat arbitrary values in between a set of normal values. Can someone kindly help me out? Feel free to go through the code again.
I have also attached a photo of serial monitor when the car is stationary.

Please post you code here (using code tags when you do) to avoid the need to download it.

If you want to post the output to the Serial monitor then please copy and paste it and post it here, again using code tags when you do.

Ah, found the problem :slight_smile: the servo wasn't getting the proper signal because the wires weren't in contact, tiny connector XD.

my car should turn when the ultrasonic sensors value for distance is equal to or lesser than zero

You might like to consider turning before the distance reaches zero and by definition it cannot ever be less than zero.