Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- //#define NUM_LEDS 356
- #define DATA_PIN 2
- #define CMD_NEW_DATA 1
- #define BAUD_RATE 115200
- // Params for width and height
- const uint8_t kMatrixWidth = 14;
- const uint8_t kMatrixHeight = 26;
- #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
- CRGB leds[ NUM_LEDS ];
- #define LAST_VISIBLE_LED 355
- uint16_t XY (uint16_t x, uint16_t y) {
- // any out of bounds address maps to the first hidden pixel
- if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
- return (LAST_VISIBLE_LED + 1);
- }
- const uint16_t XYTable[] = {
- 0, 51, 52, 103, 356, 357, 358, 361, 362, 363, 252, 303, 304, 355,
- 1, 50, 53, 102, 104, 153, 359, 360, 202, 251, 253, 302, 305, 354,
- 2, 49, 54, 101, 105, 152, 154, 201, 203, 250, 254, 301, 306, 353,
- 3, 48, 55, 100, 106, 151, 155, 200, 204, 249, 255, 300, 307, 352,
- 4, 47, 56, 99, 107, 150, 156, 199, 205, 248, 256, 299, 308, 351,
- 5, 46, 57, 98, 108, 149, 157, 198, 206, 247, 257, 298, 309, 350,
- 6, 45, 58, 97, 109, 148, 158, 197, 207, 246, 258, 297, 310, 349,
- 7, 44, 59, 96, 110, 147, 159, 196, 208, 245, 259, 296, 311, 348,
- 8, 43, 60, 95, 111, 146, 160, 195, 209, 244, 260, 295, 312, 347,
- 9, 42, 61, 94, 112, 145, 161, 194, 210, 243, 261, 294, 313, 346,
- 10, 41, 62, 93, 113, 144, 162, 193, 211, 242, 262, 293, 314, 345,
- 11, 40, 63, 92, 114, 143, 163, 192, 212, 241, 263, 292, 315, 344,
- 12, 39, 64, 91, 115, 142, 164, 191, 213, 240, 264, 291, 316, 343,
- 13, 38, 65, 90, 116, 141, 165, 190, 214, 239, 265, 290, 317, 342,
- 14, 37, 66, 89, 117, 140, 166, 189, 215, 238, 266, 289, 318, 341,
- 15, 36, 67, 88, 118, 139, 167, 188, 216, 237, 267, 288, 319, 340,
- 16, 35, 68, 87, 119, 138, 168, 187, 217, 236, 268, 287, 320, 339,
- 17, 34, 69, 86, 120, 137, 169, 186, 218, 235, 269, 286, 321, 338,
- 18, 33, 70, 85, 121, 136, 170, 185, 219, 234, 270, 285, 322, 337,
- 19, 32, 71, 84, 122, 135, 171, 184, 220, 233, 271, 284, 323, 336,
- 20, 31, 72, 83, 123, 134, 172, 183, 221, 232, 272, 283, 324, 335,
- 21, 30, 73, 82, 124, 133, 173, 182, 222, 231, 273, 282, 325, 334,
- 22, 29, 74, 81, 125, 132, 174, 181, 223, 230, 274, 281, 326, 333,
- 23, 28, 75, 80, 126, 131, 175, 180, 224, 229, 275, 280, 327, 332,
- 24, 27, 76, 79, 127, 130, 176, 179, 225, 228, 276, 279, 328, 331,
- 25, 26, 77, 78, 128, 129, 177, 178, 226, 227, 277, 278, 329, 330
- };
- uint16_t i = (y * kMatrixWidth) + x;
- uint16_t j = XYTable[i];
- return j;
- }
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- Serial.begin(BAUD_RATE);
- }
- int serialGlediator () {
- while (!Serial.available()) {}
- return Serial.read();
- }
- void loop() {
- byte r,g,b;
- int i;
- while (serialGlediator () != CMD_NEW_DATA) {}
- /*
- //This works but it handles all strips the same
- Serial.readBytes((char*)leds, NUM_LEDS*3);
- FastLED.show();
- //This also works but also handles all the strip the same
- for (i=0; i < NUM_LEDS; i++) {
- //b = serialGlediator();
- //r = serialGlediator();
- //g = serialGlediator();
- Serial.readBytes( (char*)(&leds[i]), 3);
- //leds[i].setRGB(Color(r,g,b));
- //leds[i] = CHSV( r,g,b);
- //leds.setPixel(i, Color(r,g,b));
- }
- FastLED.show();
- */
- //This doesnt work exactly but need to get led from serial and map to x and y??
- for( byte y = 0; y < kMatrixHeight; y++) {
- for( byte x = 0; x < kMatrixWidth; x++) {
- //Serial.print(XY(x,y));Serial.print("\n");
- //leds[ XY(x, y)] = CHSV( 10, 10, 10);
- Serial.readBytes( (char*)(&leds[ XY(x, y)]), 3);
- }
- }
- FastLED.show();
- }
- /* Helper functions */
- // Create a 24 bit color value from R,G,B
- unsigned int Color(byte r, byte g, byte b)
- {
- return (((unsigned int)b << 16) | ((unsigned int)r << 8) | (unsigned int)g);
- }
Advertisement
Add Comment
Please, Sign In to add comment