-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArduinoHM10Test.ino
54 lines (45 loc) · 1.26 KB
/
ArduinoHM10Test.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
/*
Arduino HM10 Bluetooth Test for Unity Plugin
Language: Wiring/Arduino
This program waits for input from the Unity app and reflects any strings back
to that app. If this app receives a single byte of 0x01 it will toggle the led
The circuit:
- connect HM10 BLE device to serial RX/TX lines
created 05 July 2018
by Tony Pitman
http://www.shatalmic.com/arduino-hm10-test
*/
int inByte = 0; // incoming serial byte
boolean ledStatus = false;
void setup() {
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
if (inByte == 0x01) {
if (ledStatus) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("Setting LED On");
ledStatus = false;
}
else {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Setting LED Off");
ledStatus = true;
}
}
else {
Serial.write(inByte);
}
}
}