Last active
January 6, 2021 06:44
-
-
Save bigjosh/9b3675b92e0c9d144c2abb73f476e523 to your computer and use it in GitHub Desktop.
Example of how to prevent sleeping on a Move38 blink - DANGER: USE WITH CARE
This file contains 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
#include "shared/blinkbios_shared_button.h" | |
#include "shared/blinkbios_shared_functions.h" | |
// Example of how to prevent a blink from going to sleep. | |
// This will keep blinking once per second until the battery goes dead. | |
// Button click will show a red flash. Note that we are making fake button presses | |
// to avoid warm sleep, so you can not reliabily detect an actual button press but you can | |
// see clicks and long presses. | |
void setup() { | |
// No setup needed for this simple example! | |
} | |
bool onFlag = false; | |
Timer nextChange; | |
void loop() { | |
if (buttonSingleClicked()) { | |
setColor( RED ); | |
nextChange.set(250); // Long enough to see | |
} | |
if (nextChange.isExpired()) { | |
if (onFlag) { | |
setColor( OFF ); | |
onFlag = false; | |
nextChange.set(950); | |
} else { | |
// Only blink breifly to save power | |
setColor(BLUE); | |
onFlag = true; | |
nextChange.set(50); | |
} | |
} | |
// These two lines will postpone sleeping. The first one postpones cold sleep and | |
// the second one postpones warm sleep. Note that this will also keep any neighbooring | |
// blinks from warm sleeping as well (they will still cold sleep). | |
BLINKBIOS_POSTPONE_SLEEP_VECTOR(); | |
blinkbios_button_block.bitflags |= BUTTON_BITFLAG_PRESSED; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment