Advertisement
atuline

sindots

May 1st, 2021
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. /*
  2.    By: ldirko (on Reddit)
  3.  
  4.   https://editor.soulmatelights.com/gallery/597-sin-dots
  5.  
  6.   Minimum width/height of 4.
  7.  
  8. */
  9.  
  10. #include <FastLED.h>
  11.  
  12. #define LED_PIN  12
  13.  
  14. const uint8_t matrixWidth  = 16;
  15. const uint8_t matrixHeight = 16;
  16.  
  17. #define NUM_LEDS (matrixWidth*matrixHeight)
  18. #define matrixSerpentineLayout true
  19.  
  20. CRGB leds[NUM_LEDS];
  21.  
  22.  
  23. void setup() {
  24.   delay(1000);
  25.   Serial.begin(115200);
  26.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  27.   FastLED.setBrightness(64);
  28. } // setup()
  29.  
  30.  
  31.  
  32. void loop () {
  33.  
  34.   EVERY_N_MILLIS(23) {
  35.     sindots();
  36.   }
  37.   FastLED.show();
  38.  
  39. } // loop()
  40.  
  41.  
  42. void sindots() {
  43.   fadeToBlackBy(leds, NUM_LEDS, 15);
  44.   byte t1 = millis() / 20;
  45.   byte t2 = sin8(t1) / 4 * 2;
  46.   for (uint16_t i = 0; i < 13; i++) {
  47.     byte x = sin8(t1 + i * 20) * matrixWidth / 256;
  48.     byte y = sin8(t2 + i * 20) * matrixHeight / 256;
  49.  
  50.     static int maxVal = 0;
  51.     if (XY(x, y) > maxVal) {maxVal = XY(x,y); Serial.println(maxVal); }
  52.    
  53.     leds[XY(x, y)] = CHSV(i * 255 / 13, 255, 255);
  54.   }
  55.   blur2d(leds, matrixWidth, matrixHeight, 16);
  56. }
  57.  
  58.  
  59.  
  60. uint16_t XY( uint8_t x, uint8_t y) {
  61.  
  62.   uint16_t i;
  63.  
  64.   if ( matrixSerpentineLayout == false) {
  65.     i = (y * matrixWidth) + x;
  66.   }
  67.  
  68.   if ( matrixSerpentineLayout == true) {
  69.     if ( y & 0x01) {
  70.       uint8_t reverseX = (matrixWidth - 1) - x;
  71.       i = (y * matrixWidth) + reverseX;
  72.     } else {
  73.       i = (y * matrixWidth) + x;
  74.     }
  75.   }
  76.   return i;
  77.  
  78. } // XY()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement