Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //2 DNA spiral with subpixel
- //16x16 rgb led matrix demo
- //Yaroslaw Turbin 04.09.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //https://www.reddit.com/r/FastLED/comments/gogs4n/i_made_7x11_matrix_for_my_ntp_clock_project_then/
- //this is update for DNA procedure https://pastebin.com/Qa8A5NvW
- //add subpixel render foк nice smooth look
- #include "FastLED.h"
- // Matrix size
- #define NUM_ROWS 16
- #define NUM_COLS 16
- // LEDs pin
- #define DATA_PIN 3
- // LED brightness
- #define BRIGHTNESS 255
- #define NUM_LEDS NUM_ROWS * NUM_COLS
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- #define speeds 30
- double freq = 3000;
- float mn =255.0/13.8;
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- fadeToBlackBy(leds, NUM_LEDS, 40);
- for (int i = 0; i < NUM_ROWS; i++)
- {
- uint16_t ms = millis();
- uint32_t x= beatsin16(speeds,0,(NUM_COLS-1)*256,0,i*freq);
- uint32_t y= i*256;
- uint32_t x1= beatsin16(speeds,0,(NUM_COLS-1)*256,0,i*freq+32768);
- CRGB col = CHSV( ms / 29+i*255/(NUM_ROWS-1), 255, beatsin8(speeds, 60, BRIGHTNESS, 0, i*mn));
- CRGB col1 = CHSV( ms / 29+i*255/(NUM_ROWS-1)+128, 255, beatsin8(speeds, 60, BRIGHTNESS, 0, i*mn + 128));
- wu_pixel (x,y,&col);
- wu_pixel (x1,y,&col1);
- }
- blur2d( leds, NUM_COLS, NUM_ROWS, 32);
- FastLED.show();
- }
- uint16_t XY (uint8_t x, uint8_t y) {return (y * NUM_COLS + x);}
- void wu_pixel(uint32_t x, uint32_t y, CRGB * col) { //awesome wu_pixel procedure by reddit u/sutaburosu
- // extract the fractional parts and derive their inverses
- uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
- // calculate the intensities for each affected pixel
- #define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
- uint8_t wu[4] = {WU_WEIGHT(ix, iy), WU_WEIGHT(xx, iy),
- WU_WEIGHT(ix, yy), WU_WEIGHT(xx, yy)};
- // multiply the intensities by the colour, and saturating-add them to the pixels
- for (uint8_t i = 0; i < 4; i++) {
- uint16_t xy = XY((x >> 8) + (i & 1), (y >> 8) + ((i >> 1) & 1));
- leds[xy].r = qadd8(leds[xy].r, col->r * wu[i] >> 8);
- leds[xy].g = qadd8(leds[xy].g, col->g * wu[i] >> 8);
- leds[xy].b = qadd8(leds[xy].b, col->b * wu[i] >> 8);
- }
- }
Add Comment
Please, Sign In to add comment