-
Notifications
You must be signed in to change notification settings - Fork 0
/
frankenweenie.ino
99 lines (94 loc) · 2.19 KB
/
frankenweenie.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
bool maximum_torque = true;
int ena1 = 5;
int in1 = 6;
int in2 = 7;
int ena2 = 10;
int in3 = 8;
int in4 = 9;
void setup() {
Serial.begin(9600);
pinMode(ena1, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(ena2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void stopMotors() {
analogWrite(ena1, 0);
analogWrite(ena2, 0);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
Serial.print(command);
switch (command) {
case 'F':
if (maximum_torque) {
analogWrite(ena1, 255);
analogWrite(ena2, 255);
} else {
analogWrite(ena1, 200);
analogWrite(ena2, 200);
}
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
case 'B':
if (maximum_torque) {
analogWrite(ena1, 255);
analogWrite(ena2, 255);
} else {
analogWrite(ena1, 200);
analogWrite(ena2, 200);
}
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 'R':
if (maximum_torque) {
analogWrite(ena1, 255);
analogWrite(ena2, 255);
} else {
analogWrite(ena1, 200);
analogWrite(ena2, 200);
}
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 'L':
if (maximum_torque) {
analogWrite(ena1, 255);
analogWrite(ena2, 255);
} else {
analogWrite(ena1, 200);
analogWrite(ena2, 200);
}
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
case 'P':
stopMotors();
delay(100);
break;
case 'S':
maximum_torque = false;
break;
case 'O':
maximum_torque = true;
break;
}
}
}