Skip to content

Instantly share code, notes, and snippets.

@Tmw
Last active February 1, 2016 21:48
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 Tmw/cbef478f5e2871b30eaf to your computer and use it in GitHub Desktop.
Save Tmw/cbef478f5e2871b30eaf to your computer and use it in GitHub Desktop.
Writing values to the brightnessMask array
void led(int x, int y, int z, int brightness){
// ensure 4-bit limited brightness
brightness = constrain(brightness, 0, 15);
int ledNr = y*4+x;
// turn 4-bit brightness into brightness mask
for (int i = 3; i >= 0; i--) {
if (brightness - (1 << i) >= 0) {
brightness -= (1 << i);
setBrightnessForLayerAddressValue(z, (ledNr*4)+i, true);
}
else{
setBrightnessForLayerAddressValue(z, (ledNr*4)+i, false);
}
}
}
void setBrightnessForLayerAddressValue(int layer, int address, bool value){
if(layer == 0){
brightnessMask_layer1[address] = value;
}
else if(layer == 1){
brightnessMask_layer2[address] = value;
}
else if(layer == 2){
brightnessMask_layer3[address] = value;
}
else if(layer == 3){
brightnessMask_layer4[address] = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment