Go Down

Topic: reading information from sd card (Read 2357 times) previous topic - next topic

victorfb

Quote
It's also nice to see that you've learned to add Serial.print() statements to see what is going on.

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?
Quote
It's so nice to see comments match the code.

I forgot to change the commentary but I am sure that didn't hinder your ability to understand the code.
Quote
Haven't we been down this road? Where is your serial output?

Quote
distance: 56
distance: 32
distance: 15
Smallest value 15
Position of smallest 2
distance: 32
distance: 45
distance: 12
Smallest value 12
Position of smallest 2
distance: 35
distance: 55
distance: 67
Smallest value 35
Position of smallest 0
distance: 42
distance: 64
distance: 78
Smallest value 42
Position of smallest 0
distance: 12
distance: 38
distance: 97
Smallest value 12
Position of smallest 0
distance: 16
distance: 59
distance: 34
Smallest value 16
Position of smallest 0

this is my serial output. It does what is suppose to do when it comes to get the values on the array to find the smallest value and the position of it

PaulS

Quote
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.


victorfb

Quote
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.

Ok I did as you said and this is what I got
Quote
distance: 30
distance: 45
distance: 15
Smallest value 15
position of smallest 2
turning right
distance: 30
distance: 45
distance: 15
Smallest value 15
position of smallest 2
turning right
distance: 32
distance: 35
distance: 45
Smallest value 32
position of smallest 0
moving forward
distance: 34
distance: 36
distance: 126
Smallest value 34
position of smallest 0
moving forward
distance: 12
distance: 45
distance: 65
Smallest value 12
position of smallest 0
turning left
distance: 15
distance: 36
distance: 126
Smallest value 15
position of smallest 0
turning 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

PaulS

Quote
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.

victorfb

Quote
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.

I did this already I put something like
Code: [Select]
if(minimum<20 && position ==1)
           turnRight();
         else
            haltMotors();

and the car would just keep turning right without stopping. and that happened for all conditions that I tested.

PaulS

Quote
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.

But, I don't want ANY conditions. Make it unconditionally call each function that makes the car move. Is the problem with the function? If so, which one(s) don't work? Or, is the problem with the hardware? Or, is it the logic in the code?

I can't see anything wrong with the code, except that those pesky { jumped back up a line, and jammed themselves up against the statements...

Go Up