/* Helper functions for an two-dimensional XY matrix of pixels.
This special 'XY' code lets you program the RGB Shades
if it's was just a plain 16x5 matrix.
Writing to and reading from the 'holes' in the layout is
also allowed; holes retain their data, it's just not displayed.
You can also test to see if you're on- or off- the layout
like this
if( XY(x,y) > LAST_VISIBLE_LED ) { ...off the layout...}
X and Y bounds checking is also included, so it is safe
to just do this without checking x or y in your code:
leds[ XY(x,y) ] == CRGB::Red;
All out of bounds coordinates map to the first hidden pixel.
https://macetech.github.io/FastLED-XY-Map-Generator/
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+-----------------------------------------------------------
0 | 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
2 | 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30
3 | 45 46 47 48 49
4 | 58 57 56 55 54 53 52 51 50
5 | 59 60 61 62 63 64 65 66 67 68 69
6 | 80 79 78 77 76 75 74 73 72 71 70
7 | 81 82 83 84 85
8 | 92 91 90 89 88 87 86
9 | 93 94 95 96 97
10 | 102 101 100 99 98
*/
#include <FastLED.h>
/*********************************************
/* Modifié pour K SIGN WILLERS LE 19-11-2021 */
/*********************************************/
#define LED_PIN 3 // Output pin for LEDs [6]
#define COLOR_ORDER RGB // Color order of LED string [RGB]
#define CHIPSET WS2811 // LED string type [WS2811]
#define BRIGHTNESS 50 // Overall brightness [50]
#define LAST_VISIBLE_LED 135 // Last LED that's visible [135]
#define MAX_MILLIAMPS 5000 // Max current in mA to draw from supply [500]
#define SAMPLE_WINDOW 100 // How many ms to sample audio for [100]
#define BTN_PIN 3 // Pin for button [3]
#define DEBOUNCE_MS 20 // Number of ms to debounce the button [20]
#define LONG_PRESS 500 // Number of ms to hold the button to count as long press [500]
#define PATTERN_TIME 10 // Seconds to show each pattern on autoChange [10]
#define kMatrixWidth 7 // Matrix width [15]
#define kMatrixHeight 13 // Matrix height [11]
#define NUM_LEDS 182 // Total number of Leds
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight) // Largest dimension of matrix
CRGB leds[ NUM_LEDS ];
/*********************************************
/* Modifié pour K SIGN WILLERS LE 19-11-2021 */
/*********************************************/
// Helper to map XY coordinates to irregular matrix
uint16_t XY (uint8_t x, uint8_t y) { // Cette fonction retourne un numéro de LED sur base des coordonnées x et y qui lui sont transmises en argument (tenant compte du mapping effectué dans la table XYTable)
// any out of bounds address maps to the first hidden pixel
if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
return (LAST_VISIBLE_LED + 1);
}
const uint8_t XYTable[] = {
1, 3, 5, 137, 138, 139, 140,
11, 9, 7, 144, 143, 142, 141,
13, 15, 17, 145, 146, 147, 148,
23, 21, 19, 153, 152, 151, 150,
25, 27, 29, 154, 93, 95, 97,
35, 33, 31, 155, 91, 101, 99,
37, 39, 77, 79, 89, 103, 105,
43, 41, 75, 81, 87, 107, 156,
45, 47, 73, 83, 85, 109, 111,
51, 49, 71, 157, 117, 115, 113,
53, 55, 69, 158, 119, 121, 123,
59, 57, 67, 159, 129, 127, 125,
61, 63, 65, 160, 131, 133, 135
};
uint8_t i = (y * kMatrixWidth) + x;
uint8_t j = XYTable[i];
return j;
}
// This function will return the right 'led index number' for
// a given set of X and Y coordinates on your matrix.
// IT DOES NOT CHECK THE COORDINATE BOUNDARIES.
// That's up to you. Don't pass it bogus values.
//
// Use the "XY" function like this:
void setup(){
Serial.begin(115200);
}
void loop(){
for( uint8_t x = 0; x < kMatrixWidth; x++) {
for( uint8_t y = 0; y < kMatrixHeight; y++) {
//Serial.print("Test");
// Serial.print(XY(x,y));
// Here's the x, y to 'led index' in action:
leds[ XY( x, y) ] = CHSV( 57, 255, 255);
leds[5]=CHSV(100, 255, 255);
leds[6]=CRGB::Aqua;
}
}
FastLED.show();
}