/* Blink_lp_BLE Turns on an LED on for one second, then off for one second, repeatedly. (c)2018 Forward Computing and Control Pty. Ltd. This example code is in the public domain. */ #include // Pin 13 has an LED connected on most Arduino boards, including NanoV2 int led = 13; bool ledOn = false; lp_timer ledTimer; const unsigned long DELAY_TIME = 1000; // ms == 1sec lp_BLESerial ble; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); ble.setName("Led Control"); // set advertised name, default name is "Nordic BLE UART" ble.begin(); // start advertising and be ready to accept connections ledTimer.startTimer(DELAY_TIME, handleLedTimer); } void loop() { sleep(); // just sleep here waiting for the timer to trigger // check for new BLE cmd 'a' starts blinking, 'b' stops blinking while (ble.available() ) { int i = ble.read(); if ('a' == i) { ledTimer.startTimer(DELAY_TIME, handleLedTimer); // start blinking } else if ('b' == i) { ledTimer.stop(); // stop blinking } } } void handleLedTimer() { ledOn = !ledOn; // toggle state if (ledOn) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) } else { digitalWrite(led, LOW); // turn the LED off by making the voltage LOW } }