Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created February 11, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbobrow/31126c1c4f776460ccff2310f3460e95 to your computer and use it in GitHub Desktop.
Save jbobrow/31126c1c4f776460ccff2310f3460e95 to your computer and use it in GitHub Desktop.
/*
* Take on the color of the dominant Blink attached
*/
byte myState = 0;
Color colors[] = {OFF, BLUE, RED, YELLOW, ORANGE, GREEN};
void setup() {
// put your setup code here, to run once:
setValueSentOnAllFaces( myState );
}
void loop() {
// put your main code here, to run repeatedly:
if ( buttonSingleClicked() ) {
myState++;
if (myState >= COUNT_OF(colors)) {
myState = 0;
}
}
FOREACH_FACE( f ) {
if ( !isValueReceivedOnFaceExpired( f ) ) {
// update to the value we see, if the value is already our value, do nothing
byte neighborState = getLastValueReceivedOnFace( f );
if ( neighborState > myState ) {
myState = neighborState;
}
}
}
setColor(dim( colors[myState], 190 + 55 * sin_d( (millis()/10) % 360)));
setValueSentOnAllFaces( myState );
}
// Sin in degrees ( standard sin() takes radians )
float sin_d( uint16_t degrees ) {
return sin( ( degrees / 360.0F ) * 2.0F * PI );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment