-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLETest.ino
62 lines (59 loc) · 1.39 KB
/
BLETest.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
#include "Boards.h"
#include <ble_mini.h>
const int pin = 4; // lets stay with pin 4.
const int pinMissed = 8;
byte buf[] = {'N','I','N','J','A'};
int incoming;
const int R = 9;
const int G = 10;
const int B = 11;
void setup() {
BLEMini_begin(57600); // start the BLE device
// Serial.begin(57600);
pinMode(pin, OUTPUT);
pinMode(pinMissed, OUTPUT);
}
void loop() {
while(BLEMini_available()) {
byte cmd = BLEMini_read(); // read command.
byte toggleState = BLEMini_read();// read 0 or 1.
byte extraData = BLEMini_read();
switch(cmd) {
case 0x01:
switch(toggleState) {
case 0x00:
digitalWrite(pin, LOW);
break;
case 0x01:
digitalWrite(pin, HIGH);
if(extraData == 0x01)
BLEMini_write_bytes(buf, 5);
break;
}
break;
case 0xA2:
switch(toggleState) {
case 0xA1:
digitalWrite(pinMissed, HIGH);
break;
case 0xA0:
digitalWrite(pinMissed, LOW);
break;
}
break;
case 0x02:
switch(extraData) {
case 0x00:
analogWrite(R, toggleState);
break;
case 0x01:
analogWrite(G, toggleState);
break;
case 0x02:
analogWrite(B, toggleState);
break;
}
break;
}
}
}