Guest User

BackPackCode

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