-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArduino_code.ino
More file actions
112 lines (100 loc) · 3.01 KB
/
Arduino_code.ino
File metadata and controls
112 lines (100 loc) · 3.01 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
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int led8 = 8, led9 = 9, led10 = 10, led11 = 11, led12 = 12, led13 = 13;
int button1State = 0;
int button2State = 0;
int dataFromBt;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(led13, OUTPUT);
}
void loop()
{
if (bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
//Serial.println((char)bluetooth.read());
dataFromBt = bluetooth.read();
if (dataFromBt == 'a') {
Serial.println("led8 on");
digitalWrite(led8, HIGH);
bluetooth.print("81");
}
if (dataFromBt == 'b') {
Serial.println("led off");
digitalWrite(led8, LOW);
bluetooth.print("80");
}
if (dataFromBt == 'c') {
Serial.println("led9 on");
digitalWrite(led9, HIGH);
bluetooth.print("91");
}
if (dataFromBt == 'd') {
Serial.println("led off");
digitalWrite(led9, LOW);
bluetooth.print("90");
}
if (dataFromBt == 'e') {
Serial.println("led10 on");
digitalWrite(led10, HIGH);
bluetooth.print("101");
}
if (dataFromBt == 'f') {
Serial.println("led off");
digitalWrite(led10, LOW);
bluetooth.print("100");
}
if (dataFromBt == 'g') {
Serial.println("led11 on");
digitalWrite(led11, HIGH);
bluetooth.print("111");
}
if (dataFromBt == 'h') {
Serial.println("led10 off");
digitalWrite(led11, LOW);
bluetooth.print("110");
}
if (dataFromBt == 'i') {
Serial.println("led12 on");
digitalWrite(led12, HIGH);
bluetooth.print("121");
}
if (dataFromBt == 'j') {
Serial.println("led12 off");
digitalWrite(led12, LOW);
bluetooth.print("120");
}
if (dataFromBt == 'k') {
Serial.println("led13 on");
digitalWrite(led13, HIGH);
bluetooth.print("131");
}
if (dataFromBt == 'l') {
Serial.println("led13 off");
digitalWrite(led13, LOW);
bluetooth.print("130");
}
}
if (Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
}