-
Notifications
You must be signed in to change notification settings - Fork 2
/
hc-05.ino
83 lines (70 loc) · 2.07 KB
/
hc-05.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
// Arduino code to control the wheelchair
//#include <SoftwareSerial.h>
//SoftwareSerial Bluetooth(3,2); // RX | TX
const int leftForward = 8;
const int leftBackward = 9;
const int rightForward = 10;
const int rightBackward = 11;
void setup() {
pinMode(leftForward , OUTPUT);
pinMode(leftBackward , OUTPUT);
pinMode(rightForward , OUTPUT);
pinMode(rightBackward , OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
//Bluetooth.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(12, HIGH);
while (Serial.available())
{
char ch = Serial.read();
if (ch == 'a') //back
{
//Serial.println("hello world");
digitalWrite(leftForward, LOW); //turn left
digitalWrite(leftBackward, HIGH);
digitalWrite(rightForward, HIGH);
digitalWrite(rightBackward, LOW);
}
else if (ch == 'l') //left
{
digitalWrite(leftForward, LOW);
digitalWrite(leftBackward, HIGH);
digitalWrite(rightForward, LOW);
digitalWrite(rightBackward, HIGH);
delay(520);
digitalWrite(leftForward, HIGH);
digitalWrite(leftBackward, LOW);
digitalWrite(rightForward, LOW);
digitalWrite(rightBackward, HIGH);
}
else if (ch == 'r') //right
{
digitalWrite(leftForward, HIGH);
digitalWrite(leftBackward, LOW);
digitalWrite(rightForward, HIGH);
digitalWrite(rightBackward, LOW);
delay(520);
digitalWrite(leftForward, HIGH);
digitalWrite(leftBackward, LOW);
digitalWrite(rightForward, LOW);
digitalWrite(rightBackward, HIGH);
}
else if (ch == 'f') //front
{
digitalWrite(leftForward, HIGH);
digitalWrite(leftBackward, LOW);
digitalWrite(rightForward, LOW);
digitalWrite(rightBackward, HIGH);
}
else if (ch == 's' || ch == 'S')
{
digitalWrite(leftForward, LOW);
digitalWrite(leftBackward, LOW);
digitalWrite(rightForward, LOW);
digitalWrite(rightBackward, LOW);
}
}
}