-
-
Save bigjosh/a94e1005fc53e10264c634972d7e0010 to your computer and use it in GitHub Desktop.
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
/* | |
* Color By Number/Neigbor | |
* | |
* An example showing how to use the blinkstate library. | |
* | |
* Each Blink broadcasts 1 to its neighbors, letting its neigbors know it's present. | |
* Each Blink displays a color based on the number of neighbors around it. | |
* | |
*/ | |
#include "blinklib.h" | |
#include "blinkstate.h" | |
// color by number of neighbors | |
Color colors[] = {dim(WHITE,5), // 0 neighbors | |
RED, // 1 neighbors | |
YELLOW, // 2 neighbors | |
GREEN, // 3 neighbors | |
CYAN, // 4 neighbors | |
BLUE, // 5 neighbors | |
MAGENTA }; // 6 neighbors | |
void setup() { | |
// put your setup code here, to run once: | |
FOREACH_FACE(i) { | |
// simple startup sequence with a ring of magenta | |
setFaceColor( i , MAGENTA ); | |
delay(100); | |
setFaceColor( i , OFF ); | |
} | |
blinkStateBegin(); | |
setState(1); | |
} | |
void loop() { | |
// count neighbors | |
int numNeighbors = 0; | |
FOREACH_FACE(i) { | |
numNeighbors+=getNeighborState(i); | |
} | |
// show color based on number of neighbors | |
setColor( colors[ numNeighbors ] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment