-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl298Test.h
199 lines (162 loc) · 5.45 KB
/
l298Test.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#pragma once
#include "gemt_interface.h"
extern void l298Test(void);
GEMTtest l298Display;
// Initialize pins
#define in1 34
#define in2 36
#define enA 46
#define in3 38
#define in4 40
#define enB 44
int value_in1 = 0;
float voltage_in1;
int value_in2 = 0;
float voltage_in2;
int value_in3 = 0;
float voltage_in3;
int value_in4 = 0;
float voltage_in4;
String l1;
String l2;
String r1;
String r2;
void test()
{
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void voltL()
{
value_in1 = analogRead(A1);
voltage_in1 = value_in1 * 5.0/1023;
Serial.print("Voltage OUT1= ");
Serial.println(voltage_in1);
value_in2 = analogRead(A2);
voltage_in2 = value_in2 * 5.0/1023;
Serial.print("Voltage OUT2= ");
Serial.println(voltage_in2);
}
void runl298Test(void)
{
l298Display.setFirstLine("L298 Info:");
l298Display.setInfoMsgLine("White Wire to ENA");
l298Display.setInfoMsgLine("Black Wire to ENB");
l298Display.setInfoMsgLine("+12 on L298 to +9V");
l298Display.setInfoMsgLine("GND on L298 to -9V");
l298Display.setInfoMsgLine("OUT1-4 to OUT1-4");
l298Display.setInfoMsgLine("Connect 9V to Header");
if(l298Display.showInfoScreen())
{
l298Display.setFirstLine("L298 Test:");
l298Display.showStaticTestScreen(l298Test);
}
}
// NOTE: Since test is constatly updating, we dont have access to click feature
// If testing interval too short we cant exit test!
unsigned long l298nTestingInterval = 1000;
unsigned long l298nPreviousMillis = 0.00;
extern void l298Test(void)
{
int x=1;
while (x<4)
{
switch (x)
{
case 1:
analogWrite(enA, 255);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
value_in1 = analogRead(A1); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in1 = value_in1 * 5.0/1023;
value_in2 = analogRead(A2);
voltage_in2 = value_in2 * 5.0/1023;
l1 = String("V-Left1: ") + String(voltage_in1, 2);
l2 = String("V-Left2: ") + String(voltage_in2, 2);
l298Display.setStaticTestFeedbackLine("Forward");
l298Display.setStaticTestFeedbackLine(l1);
l298Display.setStaticTestFeedbackLine(l2);
analogWrite(enB, 255);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
value_in3 = analogRead(A3); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in3 = value_in3 * 5.0/1023;
value_in4 = analogRead(A4);
voltage_in4 = value_in4 * 5.0/1023;
r1 = String("V-Right1: ") + String(voltage_in3, 2);
r2 = String("V-Right2: ") + String(voltage_in4, 2);
l298Display.setStaticTestFeedbackLine(r1);
l298Display.setStaticTestFeedbackLine(r2);
l298Display.showStaticTestFeedback(2000);
x=x+1;
break;
case 2:
analogWrite(enA, 255);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
value_in1 = analogRead(A1); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in1 = value_in1 * 5.0/1023;
value_in2 = analogRead(A2);
voltage_in2 = value_in2 * 5.0/1023;
l1 = String("V-Left1: ") + String(voltage_in1, 2);
l2 = String("V-Left2: ") + String(voltage_in2, 2);
l298Display.setStaticTestFeedbackLine("Backwards");
l298Display.setStaticTestFeedbackLine(l1);
l298Display.setStaticTestFeedbackLine(l2);
analogWrite(enB, 255);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
value_in3 = analogRead(A3); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in3 = value_in3 * 5.0/1023;
value_in4 = analogRead(A4);
voltage_in4 = value_in4 * 5.0/1023;
r1 = String("V-Right1: ") + String(voltage_in3, 2);
r2 = String("V-Right2: ") + String(voltage_in4, 2);
l298Display.setStaticTestFeedbackLine(r1);
l298Display.setStaticTestFeedbackLine(r2);
l298Display.showStaticTestFeedback(2000);
x=x+1;
break;
case 3:
analogWrite(enA, 255);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
value_in1 = analogRead(A1); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in1 = value_in1 * 5.0/1023;
value_in2 = analogRead(A2);
voltage_in2 = value_in2 * 5.0/1023;
l1 = String("V-Left1: ") + String(voltage_in1, 2);
l2 = String("V-Left2: ") + String(voltage_in2, 2);
l298Display.setStaticTestFeedbackLine("OFF");
l298Display.setStaticTestFeedbackLine(l1);
l298Display.setStaticTestFeedbackLine(l2);
analogWrite(enB, 255);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
value_in3 = analogRead(A3); // Voltage readings from left output. Front & backward = in1 & in2
voltage_in3 = value_in3 * 5.0/1023;
value_in4 = analogRead(A4);
voltage_in4 = value_in4 * 5.0/1023;
r1 = String("V-Right1: ") + String(voltage_in3, 2);
r2 = String("V-Right2: ") + String(voltage_in4, 2);
l298Display.setStaticTestFeedbackLine(r1);
l298Display.setStaticTestFeedbackLine(r2);
l298Display.showStaticTestFeedback(2000);
x=x+1;
break;
case 4:
l298Display.setStaticTestFeedbackLine("Null");
l298Display.showStaticTestFeedback(2000);
x=5;
break;
}
}
}