-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor_control_functions.ino
81 lines (66 loc) · 1.54 KB
/
motor_control_functions.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
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR12_64KHZ);
AF_DCMotor motor4(4, MOTOR12_64KHZ);
void moveforward()
{
motor1.setSpeed(255); // set the speed to 200/255
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void turnleft()
{
motor1.setSpeed(255); // set the speed to 200/255
motor2.setSpeed(112);
motor3.setSpeed(255);
motor4.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void turnright()
{
motor1.setSpeed(112); // set the speed to 200/255
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void movebackward()
{
motor1.setSpeed(255); // set the speed to 200/255
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}
void stopMovement()
{
motor1.run(RELEASE); // stopped
motor2.run(RELEASE); // stopped
motor3.run(RELEASE); // stopped
motor4.run(RELEASE); // stopped
}
void setup() {
}
void loop() {
moveforward();
delay(10000);
turnright();
delay(10000);
turnleft();
delay(30000);
}