-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patharduino_code.ino
More file actions
114 lines (89 loc) · 1.97 KB
/
Copy patharduino_code.ino
File metadata and controls
114 lines (89 loc) · 1.97 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
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
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int state=0;
int speed = 255;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
motor1.setSpeed(speed);
motor2.setSpeed(speed);
motor3.setSpeed(speed);
motor4.setSpeed(speed);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
//
if(Serial.available())
{
state = Serial.read() -'0';
if(state != -1 && state > 0){
light(state);
}
// Serial.print("\n");
// wait for a second
}
}
void light(int n){
if (n == 1) // forward
{
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(1000);
release();
}
else if (n == 2) // left
{
release();
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
//motor4.run(FORWARD);
delay(100);
release();
}
else if (n == 3) // right
{
release();
motor1.run(FORWARD);
motor2.run(FORWARD);
//motor3.run(FORWARD);
motor4.run(FORWARD);
delay(100);
release();
}
else if (n == 4) // reverse
{
//release();
peechyAA();
delay(1000);
release();
}
else{
release();
}
for(int i = 0 ; i < n; i++){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
delay(100);
}
}
void release(){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
void reverse(){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}