ldirko

DNA with subpixel

Sep 4th, 2020
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //2 DNA spiral with subpixel
  2. //16x16 rgb led matrix demo
  3. //Yaroslaw Turbin 04.09.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6. //https://www.reddit.com/r/FastLED/comments/gogs4n/i_made_7x11_matrix_for_my_ntp_clock_project_then/
  7.  
  8. //this is update for DNA procedure https://pastebin.com/Qa8A5NvW
  9. //add subpixel render foк nice smooth look
  10.  
  11. #include "FastLED.h"
  12.  
  13. // Matrix size
  14. #define NUM_ROWS 16
  15. #define NUM_COLS 16
  16. // LEDs pin
  17. #define DATA_PIN 3
  18. // LED brightness
  19. #define BRIGHTNESS 255
  20. #define NUM_LEDS NUM_ROWS * NUM_COLS
  21. // Define the array of leds
  22. CRGB leds[NUM_LEDS];
  23. #define speeds 30
  24. double freq = 3000;
  25. float mn =255.0/13.8;
  26.  
  27. void setup() {
  28. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  29. FastLED.setBrightness(BRIGHTNESS);
  30. }
  31.  
  32. void loop() {
  33. fadeToBlackBy(leds, NUM_LEDS, 40);  
  34.  
  35. for (int i = 0; i < NUM_ROWS; i++)      
  36. {    
  37. uint16_t ms = millis();
  38. uint32_t x= beatsin16(speeds,0,(NUM_COLS-1)*256,0,i*freq);
  39. uint32_t y= i*256;
  40. uint32_t x1= beatsin16(speeds,0,(NUM_COLS-1)*256,0,i*freq+32768);
  41.  
  42. CRGB col = CHSV( ms / 29+i*255/(NUM_ROWS-1), 255, beatsin8(speeds, 60, BRIGHTNESS, 0, i*mn));
  43. CRGB col1 = CHSV(  ms / 29+i*255/(NUM_ROWS-1)+128, 255,  beatsin8(speeds, 60, BRIGHTNESS, 0,  i*mn + 128));
  44.  
  45. wu_pixel (x,y,&col);
  46. wu_pixel (x1,y,&col1);
  47. }
  48.  
  49. blur2d( leds, NUM_COLS, NUM_ROWS, 32);
  50. FastLED.show();
  51. }
  52.  
  53. uint16_t XY (uint8_t x, uint8_t y) {return (y * NUM_COLS + x);}
  54.  
  55. void wu_pixel(uint32_t x, uint32_t y, CRGB * col) {      //awesome wu_pixel procedure by reddit u/sutaburosu
  56.   // extract the fractional parts and derive their inverses
  57.   uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
  58.   // calculate the intensities for each affected pixel
  59.   #define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
  60.   uint8_t wu[4] = {WU_WEIGHT(ix, iy), WU_WEIGHT(xx, iy),
  61.                    WU_WEIGHT(ix, yy), WU_WEIGHT(xx, yy)};
  62.   // multiply the intensities by the colour, and saturating-add them to the pixels
  63.   for (uint8_t i = 0; i < 4; i++) {
  64.     uint16_t xy = XY((x >> 8) + (i & 1), (y >> 8) + ((i >> 1) & 1));
  65.     leds[xy].r = qadd8(leds[xy].r, col->r * wu[i] >> 8);
  66.     leds[xy].g = qadd8(leds[xy].g, col->g * wu[i] >> 8);
  67.     leds[xy].b = qadd8(leds[xy].b, col->b * wu[i] >> 8);
  68.   }
  69. }
  70.  
  71.  
  72.  
Add Comment
Please, Sign In to add comment