Skip to content

Instantly share code, notes, and snippets.

@don
Last active January 26, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save don/aa2d924e0214b8b43e10a8e0ddd4243d to your computer and use it in GitHub Desktop.
Save don/aa2d924e0214b8b43e10a8e0ddd4243d to your computer and use it in GitHub Desktop.
// 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