Created
January 27, 2018 17:29
-
-
Save jbobrow/7cd5b09216cfe6ec9c24f3eec4ac0246 to your computer and use it in GitHub Desktop.
Simplest possible step function example
This file contains hidden or 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
| /* | |
| * 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