Debug log

This commit is contained in:
Denis Zheleztsov 2018-11-21 14:14:28 +03:00
parent d5a903242b
commit e30e0aebf1
Signed by: Difrex
GPG Key ID: B047A0E62A285621

17
car.ino
View File

@ -41,61 +41,72 @@ void setup() {
/* Forward */ /* Forward */
void move_forward_wheel_left() { void move_forward_wheel_left() {
if (debug) { debug_log("WH", "Move forward left wheel"); }
digitalWrite(left_wheel_1, HIGH); digitalWrite(left_wheel_1, HIGH);
digitalWrite(left_wheel_2, LOW); digitalWrite(left_wheel_2, LOW);
} }
void move_forward_wheel_right() { void move_forward_wheel_right() {
if (debug) { debug_log("WH", "Move forward right wheel"); }
digitalWrite(right_wheel_1, HIGH); digitalWrite(right_wheel_1, HIGH);
digitalWrite(right_wheel_2, LOW); digitalWrite(right_wheel_2, LOW);
} }
void move_forward() { void move_forward() {
if (debug) { debug_log("WH", "Move forward"); }
move_forward_wheel_left(); move_forward_wheel_left();
move_forward_wheel_right(); move_forward_wheel_right();
} }
/* Backward */ /* Backward */
void move_backward_wheel_left() { void move_backward_wheel_left() {
if (debug) { debug_log("WH", "Move backward left wheel"); }
digitalWrite(left_wheel_1, LOW); digitalWrite(left_wheel_1, LOW);
digitalWrite(left_wheel_2, HIGH); digitalWrite(left_wheel_2, HIGH);
} }
void move_backward_wheel_right() { void move_backward_wheel_right() {
if (debug) { debug_log("WH", "Move backward right wheel"); }
digitalWrite(right_wheel_1, LOW); digitalWrite(right_wheel_1, LOW);
digitalWrite(right_wheel_2, HIGH); digitalWrite(right_wheel_2, HIGH);
} }
void move_backward() { void move_backward() {
if (debug) { debug_log("WH", "Move backward"); }
move_backward_wheel_left(); move_backward_wheel_left();
move_backward_wheel_right(); move_backward_wheel_right();
} }
/* Stops */ /* Stops */
void stop_all() { void stop_all() {
if (debug) { debug_log("WH", "Stop the wheels"); }
for (i = 0; sizeof(wheels) - 1; i++) { for (i = 0; sizeof(wheels) - 1; i++) {
digitalWrite(wheels[i], LOW); digitalWrite(wheels[i], LOW);
} }
} }
void stop_left() { void stop_left() {
if (debug) { debug_log("WH", "Stop left wheel"); }
digitalWrite(left_wheel_1, LOW); digitalWrite(left_wheel_1, LOW);
digitalWrite(left_wheel_2, LOW); digitalWrite(left_wheel_2, LOW);
} }
void stop_right() { void stop_right() {
if (debug) { debug_log("WH", "Stop right wheel"); }
digitalWrite(right_wheel_1, LOW); digitalWrite(right_wheel_1, LOW);
digitalWrite(right_wheel_2, LOW); digitalWrite(right_wheel_2, LOW);
} }
/* Turns */ /* Turns */
void turn_left(int delayMS) { void turn_left(int delayMS) {
if (debug) { debug_log("WH", "Turn left"); }
stop_left(); stop_left();
move_forward_wheel_right(); move_forward_wheel_right();
delay(delayMS); delay(delayMS);
} }
void turn_right(int delayMS) { void turn_right(int delayMS) {
if (debug) { debug_log("WH", "Turn right"); }
stop_right(); stop_right();
move_forward_wheel_left(); move_forward_wheel_left();
delay(delayMS); delay(delayMS);
@ -125,14 +136,12 @@ int get_distance() {
digitalWrite(sensor_trigger, LOW); digitalWrite(sensor_trigger, LOW);
/* Reads the echo, returns the sound wave travel in microseconds */ /* Reads the echo, returns the sound wave travel in microseconds */
if (debug) { debug_log("US", "Get echo duration"); }
duration = pulseIn(sensor_echo, HIGH); duration = pulseIn(sensor_echo, HIGH);
if (debug) { debug_log("US", "Get echo duration"); }
/* Calculating the distance */ /* Calculating the distance */
distance = duration / 58; distance = duration / 58;
if (debug) { if (debug) { debug_log("US", "Got distance!"); }
debug_log("US", "Got distance!");
}
return distance; return distance;
} }