-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_feb25a.ino
56 lines (47 loc) · 1.05 KB
/
sketch_feb25a.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
// Include BLE files.
#include <SPI.h>
#include <boards.h>
#include <RBL_nRF8001.h>
// Define output pin
#define LED_PIN 2
void setup()
{
// Enable serial debug.
Serial.begin(9600);
Serial.println("Arduino EasyBLE example started");
Serial.println("Serial rate set to 9600");
// Enable output.
pinMode(LED_PIN, OUTPUT);
// Turn off LED.
digitalWrite(LED_PIN, LOW);
// Initialize BLE library.
ble_begin();
// Set a custom BLE name.
ble_set_name("ble_led");
Serial.println("ble_begin done!");
}
// This function is called continuously, after setup() completes.
void loop()
{
// If there's any input...
while (ble_available())
{
// Read input.
int c = ble_read();
Serial.println("Got input:");
if (c != 0)
{
// Non-zero input means "turn on LED".
Serial.println("Led: on");
digitalWrite(LED_PIN, HIGH);
}
else
{
// Input value zero means "turn off LED".
Serial.println("Led: off");
digitalWrite(LED_PIN, LOW);
}
}
// Process BLE events.
ble_do_events();
}