Last active
February 1, 2016 21:48
-
-
Save Tmw/cbef478f5e2871b30eaf to your computer and use it in GitHub Desktop.
Writing values to the brightnessMask array
This file contains 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
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