-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch_jan24a.ino
executable file
·112 lines (83 loc) · 2.22 KB
/
sketch_jan24a.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
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
int t;
const int LFOR = 11;
const int LBACK = 10;
const int RFOR = 9;
const int RBACK = 6;
//delay timing
const int Spin_D_R = 205;
const int Spin_D_L = 198;
const int Line_D = 315;
const int Orient_D = 60;
void setup() {
pinMode(LFOR,OUTPUT); //left motors forward
pinMode(LBACK,OUTPUT); //left motors reverse
pinMode(RFOR,OUTPUT); //right motors forward-+
pinMode(RBACK,OUTPUT); //right motors reverse
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println("INSTRUCTION: ");
Serial.println(t);
Serial.print("\n");
if(t == 55){ //move forward(all motors rotate in forward direction)
digitalWrite(LFOR,HIGH);
digitalWrite(RFOR,HIGH);
digitalWrite(LBACK,LOW);
digitalWrite(RBACK,LOW);
delay(Line_D);
// digitalWrite(RFOR,HIGH);
// digitalWrite(LBACK,HIGH);
// digitalWrite(LFOR,LOW);
// digitalWrite(RBACK,LOW);
// delay(Orient_D);
digitalWrite(LFOR,LOW);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
digitalWrite(RBACK,LOW);
}
else if(t == 54){
//move reverse (all motors rotate in reverse direction)
digitalWrite(LBACK,HIGH);
digitalWrite(RBACK,HIGH);
digitalWrite(LFOR,LOW);
digitalWrite(RFOR,LOW);
delay(Line_D);
digitalWrite(LFOR,LOW);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
digitalWrite(RBACK,LOW);
}
else if(t == 53){ //turn LEFT (right side motors rotate in forward direction, left side motors rotate backward)
digitalWrite(RFOR,HIGH);
digitalWrite(LBACK,HIGH);
digitalWrite(LFOR,LOW);
digitalWrite(RBACK,LOW);
delay(Spin_D_L);
digitalWrite(LFOR,LOW);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
digitalWrite(RBACK,LOW);
}
else if(t == 52){ //turn RT (left side motors rotate in forward direction, right side motors rotate backward)
digitalWrite(LFOR,HIGH);
digitalWrite(RBACK,HIGH);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
delay(Spin_D_R);
digitalWrite(LFOR,LOW);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
digitalWrite(RBACK,LOW);
}
else if(t == 51){
//STOP (all motors stop)
digitalWrite(LFOR,LOW);
digitalWrite(LBACK,LOW);
digitalWrite(RFOR,LOW);
digitalWrite(RBACK,LOW);
}
delay(100);
}
}