forked from Pedro4064/ESP32_BLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP32_BLE.ino
54 lines (37 loc) · 1.16 KB
/
ESP32_BLE.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
#include "BLE.h"
#define log(x) Serial.println(x);
Bluetooth::BLE bluetooth;
// Sensor sensor;
void setup()
{
// initialize the serial monitor
Serial.begin(115200);
// Add the characteristics that will be used
bluetooth.setDeviceName("Pedro's RunPod");
bluetooth.add_characteristic("Potato", "fbed8ddc-109f-11eb-adc1-0242ac120002");
bluetooth.add_characteristic("Pudim", "16dc549c-10a1-11eb-adc1-0242ac120002");
// Initialize the BLE
bluetooth.begin();
}
void loop() {
delay(1000);
//If a device connected to the ESP32, begin the processes, otherwise keep scanning.
if(Bluetooth::BLE::deviceConnected )
{
log("Device connected!!");
// Counter that send every odd number to the potato characteristic and every even to the Pudim characteristic
int i = 0;
while(true){
i++;
if(i%2 == 0){
bluetooth.use_characteristic("Potato"); // Change to the specific characteristic
}
else{
bluetooth.use_characteristic("Pudim"); // Change to the specific characteristic
}
// Send the value of i and notify
bluetooth.sendDataPoint(i);
delay(500);
}
}
}