Skip to content

Instantly share code, notes, and snippets.

@bigjosh
Forked from jbobrow/ColorByNeighbor.ino
Created October 31, 2017 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigjosh/a94e1005fc53e10264c634972d7e0010 to your computer and use it in GitHub Desktop.
Save bigjosh/a94e1005fc53e10264c634972d7e0010 to your computer and use it in GitHub Desktop.
/*
* 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