Index

auto-plow / f9654fb

A wheelchair motor-propelled battery-powered ESP32-driven remote control snow plow.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4112 Jan 2019 21:36b75b51aAdd more conditionalsjoshuas31200N

Blob @ auto-plow / src / ard1 / ard1.cpp

text/plain3016 bytesdownload raw
1#include "Arduino.h"
2#include "ard1.h"
3#include "serial.h"
4#include "reset.h"
5
6
7void oninput(String message);
8
9// One time
10void setup() {
11 digitalWrite(PIN_RESET, HIGH);
12 serial();
13 Serial.println("ARD1: Motor Controller Active");
14 pinMode(PIN_BRAKES, OUTPUT);
15 pinMode(PIN_MR_D, OUTPUT);
16 pinMode(PIN_MR_R, OUTPUT);
17 pinMode(PIN_ML_D, OUTPUT);
18 pinMode(PIN_ML_R, OUTPUT);
19}
20
21int brakes = 1;
22
23void oninput (String message) {
24 Serial.print("ARD1: Received information - ");
25 Serial.println(message);
26 if (message == String("Restart")) {
27 Serial.println("ARD1: Restarting...");
28 reset();
29 } else if (message == String("b0")) {
30 Serial.println("ARD1: Turning brakes off");
31 brakes = 0;
32 digitalWrite(PIN_BRAKES, HIGH);
33 } else if (message == String("b1")) {
34 Serial.println("ARD1: Turning brakes on");
35 brakes = 1;
36 digitalWrite(PIN_MR_D, LOW);
37 digitalWrite(PIN_MR_R, LOW);
38 digitalWrite(PIN_ML_D, LOW);
39 digitalWrite(PIN_ML_R, LOW);
40 delay(CHANGE_DELAY);
41 digitalWrite(PIN_BRAKES, LOW);
42 }
43 if (brakes == 1) return;
44 if (message == String("mr0")) {
45 Serial.println("ARD1: Turning MotorRight off");
46 digitalWrite(PIN_MR_D, LOW);
47 digitalWrite(PIN_MR_R, LOW);
48 } else if (message == String("mr1")) {
49 Serial.println("ARD1: Turning MotorRight on (drive)");
50 digitalWrite(PIN_MR_R, LOW);
51 delay(CHANGE_DELAY);
52 digitalWrite(PIN_MR_D, HIGH);
53 } else if (message == String("mr-1")) {
54 Serial.println("ARD1: Turning MotorRight on (reverse)");
55 digitalWrite(PIN_MR_D, LOW);
56 delay(CHANGE_DELAY);
57 digitalWrite(PIN_MR_R, HIGH);
58 } else if (message == String("ml0")) {
59 Serial.println("ARD1: Turning MotorLeft off");
60 digitalWrite(PIN_ML_D, LOW);
61 digitalWrite(PIN_ML_R, LOW);
62 } else if (message == String("ml1")) {
63 Serial.println("ARD1: Turning MotorLeft on (drive)");
64 digitalWrite(PIN_ML_R, LOW);
65 delay(CHANGE_DELAY);
66 digitalWrite(PIN_ML_D, HIGH);
67 } else if (message == String("ml-1")) {
68 Serial.println("ARD1: Turning MotorLeft on (reverse)");
69 digitalWrite(PIN_ML_D, LOW);
70 delay(CHANGE_DELAY);
71 digitalWrite(PIN_ML_R, HIGH);
72 } else if (message == String("m0")) {
73 Serial.println("ARD1: Turning both motors off");
74 digitalWrite(PIN_MR_D, LOW);
75 digitalWrite(PIN_MR_R, LOW);
76 digitalWrite(PIN_ML_D, LOW);
77 digitalWrite(PIN_ML_R, LOW);
78 } else if (message == String("m1")) {
79 Serial.println("ARD1: Turning both motors on (Drive)");
80 digitalWrite(PIN_MR_R, LOW);
81 digitalWrite(PIN_ML_R, LOW);
82 delay(CHANGE_DELAY);
83 digitalWrite(PIN_MR_D, HIGH);
84 digitalWrite(PIN_ML_D, HIGH);
85 } else if (message == String("m-1")) {
86 Serial.println("ARD1: Turning both motors on (Reverse)");
87 digitalWrite(PIN_MR_D, LOW);
88 digitalWrite(PIN_ML_D, LOW);
89 delay(CHANGE_DELAY);
90 digitalWrite(PIN_MR_R, HIGH);
91 digitalWrite(PIN_ML_R, HIGH);
92 }
93}
94
95// Repeatedly
96void loop() {
97 if (Serial.available() > 0) oninput(Serial.readStringUntil(';'));
98 delay(500);
99}
100