diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/homekit_lightbulb/homekit_lightbulb.ino b/libraries/Bluefruit52Lib/examples/Peripheral/homekit_lightbulb/homekit_lightbulb.ino new file mode 100644 index 00000000..22c90186 --- /dev/null +++ b/libraries/Bluefruit52Lib/examples/Peripheral/homekit_lightbulb/homekit_lightbulb.ino @@ -0,0 +1,68 @@ +/********************************************************************* + This is an example for our nRF52 based Bluefruit LE modules + + Pick one up today in the adafruit shop! + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + MIT license, check LICENSE for more information + All text above, and the splash screen below must be included in + any redistribution +*********************************************************************/ + +#include +#include + +HAPAccessoryInfo hap_info; + +void setup() +{ + Serial.begin(115200); + + Serial.println("Bluefruit52 Homekit Light Bulb Example"); + Serial.println("--------------------------\n"); + + Bluefruit.begin(); + // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(4); + Bluefruit.setName("Bluefruit52"); + + hap_info.begin(); + + // Set up and start advertising + startAdv(); + + dbgMemInfo(); +} + +void startAdv(void) +{ + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + Bluefruit.Advertising.addName(); + + /* Start Advertising + * - Enable auto advertising if disconnected + * - Interval: fast mode = 20 ms, slow mode = 152.5 ms + * - Timeout for fast mode is 30 seconds + * - Start(timeout) with timeout = 0 will advertise forever (until connected) + * + * For recommended advertising interval + * https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds +} + +void loop() +{ + // Toggle both LEDs every 1 second + digitalToggle(LED_RED); + delay(1000); +} +