-
Notifications
You must be signed in to change notification settings - Fork 1
/
motor_test.ino
74 lines (67 loc) · 1.32 KB
/
motor_test.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
#include <AFMotor.h>
AF_DCMotor m1(1);
AF_DCMotor m2(2);
AF_DCMotor m3(3);
AF_DCMotor m4(4);
int state = 0;
unsigned long lastMsg = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Motor test!");
m1.setSpeed(255);
m2.setSpeed(255);
m3.setSpeed(255);
m4.setSpeed(255);
}
void loop()
{
// Checks whether data is comming from the serial port
if(Serial.available() > 0)
{
state = Serial.read(); // Reads the data from the serial port
lastMsg = millis();
}
else
{
if (millis() - lastMsg > 200)
{
state = 0;
}
}
if (state == 'w')
{
m1.run(FORWARD);
m2.run(FORWARD);
m3.run(FORWARD);
m4.run(FORWARD);
}
else if (state == 's')
{
m1.run(BACKWARD);
m2.run(BACKWARD);
m3.run(BACKWARD);
m4.run(BACKWARD);
}
else if (state == 'a')
{
m1.run(BACKWARD);
m2.run(FORWARD);
m3.run(FORWARD);
m4.run(BACKWARD);
}
else if (state == 'd')
{
m1.run(FORWARD);
m2.run(BACKWARD);
m3.run(BACKWARD);
m4.run(FORWARD);
}
else
{
m1.run(RELEASE);
m2.run(RELEASE);
m3.run(RELEASE);
m4.run(RELEASE);
}
}