Last active
June 17, 2020 11:30
-
-
Save sutaburosu/790860575a4421b0005b54aef9e50227 to your computer and use it in GitHub Desktop.
A more flexible XY() mapping function for FastLED
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
#define kMatrixWidth 16 | |
#define kMatrixHeight 16 | |
#define kMatrixSerpentine true | |
#define kMatrixRowMajor true | |
#define kMatrixFlipMajor true | |
#define kMatrixFlipMinor false | |
#define NUM_LEDS ((kMatrixWidth) * (kMatrixHeight)) | |
CRGB leds[NUM_LEDS + 1]; // 1 extra for XY() to use when out-of-bounds | |
uint16_t XY(uint8_t x, uint8_t y) { | |
uint8_t major, minor, sz_major, sz_minor; | |
if (x >= kMatrixWidth || y >= kMatrixHeight) return NUM_LEDS; | |
if (kMatrixRowMajor) | |
major = x, minor = y, sz_major = kMatrixWidth, sz_minor = kMatrixHeight; | |
else | |
major = y, minor = x, sz_major = kMatrixHeight, sz_minor = kMatrixWidth; | |
if (kMatrixFlipMajor ^ (minor & 1 && kMatrixSerpentine)) | |
major = sz_major - 1 - major; | |
if (kMatrixFlipMinor) | |
minor = sz_minor - 1 - minor; | |
return (uint16_t) minor * sz_major + major; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment