Debug log
This commit is contained in:
parent
d5a903242b
commit
e30e0aebf1
17
car.ino
17
car.ino
@ -41,61 +41,72 @@ void setup() {
|
||||
|
||||
/* Forward */
|
||||
void move_forward_wheel_left() {
|
||||
if (debug) { debug_log("WH", "Move forward left wheel"); }
|
||||
digitalWrite(left_wheel_1, HIGH);
|
||||
digitalWrite(left_wheel_2, LOW);
|
||||
}
|
||||
|
||||
void move_forward_wheel_right() {
|
||||
if (debug) { debug_log("WH", "Move forward right wheel"); }
|
||||
digitalWrite(right_wheel_1, HIGH);
|
||||
digitalWrite(right_wheel_2, LOW);
|
||||
}
|
||||
|
||||
void move_forward() {
|
||||
if (debug) { debug_log("WH", "Move forward"); }
|
||||
move_forward_wheel_left();
|
||||
move_forward_wheel_right();
|
||||
}
|
||||
|
||||
/* Backward */
|
||||
void move_backward_wheel_left() {
|
||||
if (debug) { debug_log("WH", "Move backward left wheel"); }
|
||||
digitalWrite(left_wheel_1, LOW);
|
||||
digitalWrite(left_wheel_2, HIGH);
|
||||
}
|
||||
|
||||
void move_backward_wheel_right() {
|
||||
if (debug) { debug_log("WH", "Move backward right wheel"); }
|
||||
digitalWrite(right_wheel_1, LOW);
|
||||
digitalWrite(right_wheel_2, HIGH);
|
||||
}
|
||||
|
||||
void move_backward() {
|
||||
if (debug) { debug_log("WH", "Move backward"); }
|
||||
move_backward_wheel_left();
|
||||
move_backward_wheel_right();
|
||||
}
|
||||
|
||||
/* Stops */
|
||||
void stop_all() {
|
||||
if (debug) { debug_log("WH", "Stop the wheels"); }
|
||||
for (i = 0; sizeof(wheels) - 1; i++) {
|
||||
digitalWrite(wheels[i], LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void stop_left() {
|
||||
if (debug) { debug_log("WH", "Stop left wheel"); }
|
||||
digitalWrite(left_wheel_1, LOW);
|
||||
digitalWrite(left_wheel_2, LOW);
|
||||
}
|
||||
|
||||
void stop_right() {
|
||||
if (debug) { debug_log("WH", "Stop right wheel"); }
|
||||
digitalWrite(right_wheel_1, LOW);
|
||||
digitalWrite(right_wheel_2, LOW);
|
||||
}
|
||||
|
||||
/* Turns */
|
||||
void turn_left(int delayMS) {
|
||||
if (debug) { debug_log("WH", "Turn left"); }
|
||||
stop_left();
|
||||
move_forward_wheel_right();
|
||||
delay(delayMS);
|
||||
}
|
||||
|
||||
void turn_right(int delayMS) {
|
||||
if (debug) { debug_log("WH", "Turn right"); }
|
||||
stop_right();
|
||||
move_forward_wheel_left();
|
||||
delay(delayMS);
|
||||
@ -125,14 +136,12 @@ int get_distance() {
|
||||
digitalWrite(sensor_trigger, LOW);
|
||||
|
||||
/* Reads the echo, returns the sound wave travel in microseconds */
|
||||
if (debug) { debug_log("US", "Get echo duration"); }
|
||||
duration = pulseIn(sensor_echo, HIGH);
|
||||
if (debug) { debug_log("US", "Get echo duration"); }
|
||||
|
||||
/* Calculating the distance */
|
||||
distance = duration / 58;
|
||||
if (debug) {
|
||||
debug_log("US", "Got distance!");
|
||||
}
|
||||
if (debug) { debug_log("US", "Got distance!"); }
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user