It's also nice to see that you've learned to add Serial.print() statements to see what is going on.
It's so nice to see comments match the code.
Haven't we been down this road? Where is your serial output?
distance: 56distance: 32distance: 15Smallest value 15Position of smallest 2distance: 32distance: 45distance: 12Smallest value 12Position of smallest 2distance: 35distance: 55distance: 67Smallest value 35Position of smallest 0distance: 42distance: 64distance: 78Smallest value 42Position of smallest 0distance: 12distance: 38distance: 97Smallest value 12Position of smallest 0distance: 16distance: 59distance: 34Smallest value 16Position of smallest 0
This might be a stupid question, but how can I use Serial.print on the if statements, if all I have there is functions and no variables?
Well, you could put Serial.println("moving forward"); in the block that is supposed to move the car forward. If you see "moving forward" on the Serial Monitor, but the car is turning left, you know one thing. If you see "moving forward" and the car is moving forward, you know something else.
distance: 30distance: 45distance: 15Smallest value 15position of smallest 2turning rightdistance: 30distance: 45distance: 15Smallest value 15position of smallest 2turning rightdistance: 32distance: 35distance: 45Smallest value 32position of smallest 0moving forwarddistance: 34distance: 36distance: 126Smallest value 34position of smallest 0moving forwarddistance: 12distance: 45distance: 65Smallest value 12position of smallest 0turning leftdistance: 15distance: 36distance: 126Smallest value 15position of smallest 0turning left
so, the program is doing everything what is suppose to do but the hardware is not responding to it. It looks like the car get stuck at turning right and don't do anything anymore
So, now you need to create several test sketches. In one, call turnRight(). Make sure the car does what it is supposed to. If it does, change the call to turnLeft(). Again, make sure the car does what it is supposed to. Then, call forward(), haltMotors(), etc. and verify each function independently.
if(minimum<20 && position ==1) turnRight(); else haltMotors();
I did this already I put something like...and the car would just keep turning right without stopping. and that happened for all conditions that I tested.
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16