Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 3
- #define COLOR_ORDER GRB
- #define CHIPSET WS2812B
- #define BRIGHTNESS 200
- const uint8_t kMatrixWidth = 12; //Maximum width of the matrix
- const uint8_t kMatrixHeight = 13; //Maximum width of the matrix
- #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
- CRGB leds[NUM_LEDS];
- uint8_t brightness = BRIGHTNESS;
- #define LAST_VISIBLE_LED 114
- 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[] = {
- 281, 282, 283, 284, 285, 286, 287, 110, 288, 111, 289, 112, 290, 113, 291, 114, 292, 293, 294, 295, 296, 297, 298,
- 280, 279, 278, 277, 276, 275, 109, 274, 108, 273, 107, 272, 106, 271, 105, 270, 104, 269, 268, 267, 266, 265, 264,
- 248, 249, 250, 251, 252, 97, 253, 98, 254, 99, 255, 100, 256, 101, 257, 102, 258, 103, 259, 260, 261, 262, 263,
- 247, 246, 245, 244, 96, 243, 95, 242, 94, 241, 93, 240, 92, 239, 91, 238, 90, 237, 89, 236, 235, 234, 233,
- 219, 220, 221, 80, 222, 81, 223, 82, 224, 83, 225, 84, 226, 85, 227, 86, 228, 87, 229, 88, 230, 231, 232,
- 218, 217, 79, 216, 78, 215, 77, 214, 76, 213, 75, 212, 74, 211, 73, 210, 72, 209, 71, 208, 70, 207, 206,
- 194, 59, 195, 60, 196, 61, 197, 62, 198, 63, 199, 64, 200, 65, 201, 66, 202, 67, 203, 68, 204, 69, 205,
- 58, 193, 57, 192, 56, 191, 55, 190, 54, 189, 53, 188, 52, 187, 51, 186, 50, 185, 49, 184, 48, 183, 47,
- 171, 36, 172, 37, 173, 38, 174, 39, 175, 40, 176, 41, 177, 42, 178, 43, 179, 44, 180, 45, 181, 46, 182,
- 35, 170, 34, 169, 33, 168, 32, 167, 31, 166, 30, 165, 29, 164, 28, 163, 27, 162, 26, 161, 25, 160, 24,
- 144, 145, 146, 147, 148, 17, 149, 18, 150, 19, 151, 20, 152, 21, 153, 22, 154, 23, 155, 156, 157, 158, 159,
- 143, 142, 141, 140, 16, 139, 15, 138, 14, 137, 13, 136, 12, 135, 11, 134, 10, 133, 9, 132, 131, 130, 129,
- 115, 116, 117, 0, 118, 1, 119, 2, 120, 3, 121, 4, 122, 5, 123, 6, 124, 7, 125, 8, 126, 127, 128
- };
- uint16_t i = (y * kMatrixWidth) + x;
- uint16_t j = XYTable[i];
- return j;
- }
- void setup() {
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
- FastLED.setBrightness( BRIGHTNESS );
- }
- void loop()
- {
- uint32_t ms = millis();
- int32_t yHueDelta32 = ((int32_t)cos16( ms * (27/1) ) * (350 / kMatrixWidth));
- int32_t xHueDelta32 = ((int32_t)cos16( ms * (39/1) ) * (310 / kMatrixHeight));
- DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
- if( ms < 5000 ) {
- FastLED.setBrightness( scale8( BRIGHTNESS, (ms * 256) / 5000));
- } else {
- FastLED.setBrightness(BRIGHTNESS);
- }
- FastLED.show();
- }
- void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
- {
- byte lineStartHue = startHue8;
- for( byte y = 0; y < kMatrixHeight; y++) {
- lineStartHue += yHueDelta8;
- byte pixelHue = lineStartHue;
- for( byte x = 0; x < kMatrixWidth; x++) {
- pixelHue += xHueDelta8;
- leds[ XY(x, y)] = CHSV( pixelHue, 255, 255);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment