Index

auto-plow / f72e660

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4313 Jan 2019 17:18f72e660Fix Arduino pin pullup for resetingjoshuas3132N

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

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