Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created January 27, 2018 17:29
Show Gist options
  • Save jbobrow/7cd5b09216cfe6ec9c24f3eec4ac0246 to your computer and use it in GitHub Desktop.
Save jbobrow/7cd5b09216cfe6ec9c24f3eec4ac0246 to your computer and use it in GitHub Desktop.
Simplest possible step function example
/*
* Prototype Step Function
*
* A button press sends step from a single Blink
* All Blinks call their step function
*
* Step is special in that it leaves getNeighborState as the value before step happened...
*/
#include "blinklib.h"
#include "blinkstate.h"
#include "blinkani.h"
#define STEP_SEND_DURATION 200
#define STEP_BUFFER 100
Timer stepSendTimeout;
Timer stepReceiveTimeout;
enum state {
BREATHE,
STEP
};
void setup() {
// put your setup code here, to run once:
blinkStateBegin();
blinkAniBegin();
setState(BREATHE);
}
void loop() {
// put your main code here, to run repeatedly:
if( buttonSingleClicked() ) {
if( stepSendTimeout.isExpired() ) {
step();
}
}
// check neighbors for step
FOREACH_FACE(f) {
if( getNeighborState(f) == STEP ) {
if( stepReceiveTimeout.isExpired() ) {
step();
}
}
}
if( stepSendTimeout.isExpired() ) {
setState(BREATHE);
}
}
void step() {
setState(STEP);
stepSendTimeout.setMSFromNow(STEP_SEND_DURATION);
stepReceiveTimeout.setMSFromNow(STEP_SEND_DURATION + STEP_BUFFER);
blink(WHITE, 300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment