-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFour Wheel Drive
More file actions
56 lines (40 loc) · 1.1 KB
/
Four Wheel Drive
File metadata and controls
56 lines (40 loc) · 1.1 KB
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
#include <AFMotor.h> //motor sheild library
AF_DCMotor mot1 (1); //defines [back right] motor name; "(1)" is which motor slot it's in
AF_DCMotor mot2 (2); //defines [front right] motor name
AF_DCMotor mot3 (3); //defines [back left] motor name
AF_DCMotor mot4 (4); //defines [front left] motor name
void setup() {
mot1.setSpeed(255); //give external power to motors 1-4
mot2.setSpeed(255); // ^
mot3.setSpeed(255); // ^
mot4.setSpeed(255); // ^
}
void loop() {
// mot#.run(FORWARD); |moves motor one way
// mot#.run(BACKWARD); |moves motor the other way
// mot#.run(RELEASE); |stop moving
// delay(#); |how long previous action is carried out (in milliseconds) (1 second = 1000 milliseconds)
// move forward
mot1.run(FORWARD);
mot2.run(FORWARD);
mot3.run(FORWARD);
mot4.run(FORWARD);
delay(2000);
// stop moving
mot1.run(RELEASE);
mot2.run(RELEASE);
mot3.run(RELEASE);
mot4.run(RELEASE);
delay(2000);
// turn right
mot1.run(FORWARD);
mot2.run(FORWARD);
mot3.run(BACKWARD);
mot4.run(BACKWARD);
// stop moving
mot1.run(RELEASE);
mot2.run(RELEASE);
mot3.run(RELEASE);
mot4.run(RELEASE);
delay(2000);
}