-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.ino
More file actions
78 lines (67 loc) · 1.54 KB
/
src.ino
File metadata and controls
78 lines (67 loc) · 1.54 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
/*
Controlling LED strip with BLE AT-09
authored by @byeCl0ud
*/
#include <SoftwareSerial.h>
#include <RGBEffects.h>
int red = 4;
int green = 5;
int blue = 6;
RGBEffects rgbEffects( red; green; blue ); // digital output pins for LED strip
SoftwareSerial mySerial(2, 3); // RX, TX pins
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
/* setup BLE module */
// sendCommand("AT");
sendCommand("AT+ROLE0");
sendCommand("AT+UUID0xFF00");
sendCommand("AT+CHAR0xFF01");
sendCommand("AT+NAMEbleRGB");
Serial.println("Setup done successfully");
}
void sendCommand(const char * command){
Serial.print("Command send :");
Serial.println(command);
mySerial.println(command);
//wait some time
delay(100);
char reply[100];
int i = 0;
while (mySerial.available()) {
reply[i] = mySerial.read();
i += 1;
}
//end the string
reply[i] = '\0';
Serial.print(reply);
Serial.println("Reply successful");
}
int readSerial(){
char reply[50];
int i = 0;
while (mySerial.available()) {
reply[i] = mySerial.read();
i += 1;
}
//end the string
reply[i] = '\0';
if(strlen(reply) > 0){
Serial.println(reply);
Serial.println("Houston we have a signal!");
}
/* hardcoded effect type converter to */
return LEDmode;
}
void loop() {
char ctrl;
ctrl=readSerial(); // read commands send from iPhone
Serial.print("String read from BLE is");
Serial.println(ctrl);
if(strlen(ctrl) > 0){
rgbEffects.setEffect(RGBEffectType ctrl);
Serial.print("Changing effect to");
Serial.println(ctrl);
}
delay(1000);
}