-
Notifications
You must be signed in to change notification settings - Fork 0
/
brainchair_ino.ino
89 lines (85 loc) · 1.77 KB
/
brainchair_ino.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
#define BAUDRATE 9600
const int MotR_A = 3;
const int MotR_B = 5;
const int MotL_A = 6;
const int MotL_B = 9;
byte GetValue;
void setup()
{
Serial.begin(BAUDRATE);
pinMode(MotR_A, OUTPUT);
pinMode(MotR_B, OUTPUT);
pinMode(MotL_A, OUTPUT);
pinMode(MotL_B, OUTPUT);
}
byte ReadOneByte() // One Byte Read Function
{
int ByteRead;
while(!Serial.available());
ByteRead = Serial.read();
return ByteRead;
}
void loop()
{
GetValue = ReadOneByte();
switch(GetValue)
{
case 'L':
Robot_Left();
delay(4000);
Robot_Stop();
break;
case 'R':
Robot_Right();
delay(4000);
Robot_Stop();
break;
case 'F':
Robot_Forword();
break;
case 'B':
Robot_Reverse();
break;
case 'G':
Robot_Forword();
break;
case 'S':
Robot_Stop();
break;
}
}
void Robot_Forword()
{
digitalWrite(MotR_A, LOW);
digitalWrite(MotR_B, HIGH);
digitalWrite(MotL_B, LOW);
digitalWrite(MotL_A, HIGH);
}
void Robot_Reverse()
{
digitalWrite(MotR_A, HIGH);
digitalWrite(MotR_B, LOW);
digitalWrite(MotL_B, HIGH);
digitalWrite(MotL_A, LOW);
}
void Robot_Right()
{
digitalWrite(MotR_A, HIGH);
digitalWrite(MotR_B, LOW);
digitalWrite(MotL_B, LOW);
digitalWrite(MotL_A, HIGH);
}
void Robot_Left()
{
digitalWrite(MotR_A, LOW);
digitalWrite(MotR_B, HIGH);
digitalWrite(MotL_B, HIGH);
digitalWrite(MotL_A, LOW);
}
void Robot_Stop()
{
digitalWrite(MotR_A, LOW);
digitalWrite(MotR_B, LOW);
digitalWrite(MotL_B, LOW);
digitalWrite(MotL_A, LOW);
}