Last active
January 26, 2018 15:54
-
-
Save don/aa2d924e0214b8b43e10a8e0ddd4243d to your computer and use it in GitHub Desktop.
BroadcastCount.ino https://gist.github.com/don/536d9f1d605d9bfffcd99b5716a72cb4 with v2 APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Broadcast Characteristic Value | |
// Simple counter that broadcasts a value | |
// Use v2 of CurieBLE library | |
#include <CurieBLE.h> // Arduino 101 | |
uint8_t value = 0; | |
unsigned long previousMillis = 0; // will store last time counter was updated | |
unsigned short interval = 1000; // interval at which to update counter (milliseconds) | |
BLEService service = BLEService("EEE0"); | |
BLEShortCharacteristic characteristic = BLEShortCharacteristic("EEE1", BLERead | BLENotify | BLEBroadcast); | |
void setup() { | |
Serial.begin(9600); | |
BLE.begin(); | |
BLE.setLocalName("BLEBroadcast"); | |
BLE.setAdvertisedServiceUuid(service.uuid()); | |
service.addCharacteristic(characteristic); | |
BLE.addService(service); | |
BLE.setConnectable(true); | |
characteristic.setValue(value); | |
characteristic.broadcast(); | |
Serial.println(F("BLE Broadcast Count v2")); | |
} | |
void loop() { | |
BLE.poll(); | |
if (millis() - previousMillis > interval) { | |
characteristic.setValue(value); | |
value++; | |
previousMillis = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment