-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrichard_bt.ino
91 lines (72 loc) · 2 KB
/
richard_bt.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
#include <SoftwareSerial.h>
int out1 = 7;
int out2 = 8;
int out3 = 9;
int out4 = 10;
int out5 = 11;
int out6 = 12;
String cmd1;
String cmd2;
String cmd3;
String cmd4;
String cmd = "";
SoftwareSerial bt(2, 3);
void setup() {
bt.begin(9600);
Serial.begin(9600);
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
pinMode(out3, OUTPUT);
pinMode(out4, OUTPUT);
pinMode(out5, OUTPUT);
pinMode(out6, OUTPUT);
Serial.println("\n\n--------------------\ndémarrage...");
}
void loop() {
while (bt.available() > 0) {
cmd = bt.readString();
cmd.replace(" ",";");
cmd.replace("\n", ";");
cmd1 = cmd.substring(0, 8);
cmd2 = cmd.substring(10, 18);
cmd3 = cmd.substring(20, 28);
cmd4 = cmd.substring(30, 38);
Serial.print("\nBT RX: "+cmd);
if (cmd != "") {
// Serial.println(cmdWord+"\n"+cmdRoom+"\n"+cmdDevice+"\n");
Serial.println("\n\nSUM(cmd): "+cmd1+cmd2+cmd3+cmd4);
if(cmd1.equals("chamb1ON")){
digitalWrite(out1, HIGH);
Serial.println(cmd1+": chambre 1 allumée\n");
}
if(cmd1.equals("chamb1OF")){
digitalWrite(out1, LOW);
Serial.println(cmd1+": chambre 1 éteinte\n");
}
if(cmd2.equals("chamb2ON")){
digitalWrite(out2, HIGH);
Serial.println(cmd2+": chambre 2 allumée\n");
}
if(cmd2.equals("chamb2OF")){
digitalWrite(out2, LOW);
Serial.println(cmd2+": chambre 2 éteinte\n");
}
if(cmd3.equals("salon1ON")){
digitalWrite(out3, HIGH);
Serial.println(cmd3+": salon 1 allumée\n");
}
if(cmd3.equals("salon1OF")){
digitalWrite(out3, LOW);
Serial.println(cmd3+": salon 1 éteinte\n");
}
if(cmd4.equals("salon2ON")){
digitalWrite(out4, HIGH);
Serial.println(cmd4+": salon 2 allumée\n");
}
if(cmd4.equals("salon2OF")){
digitalWrite(out4, LOW);
Serial.println(cmd4+": salon 2 éteinte\n");
}
}
}
}