Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test subpixel render
- //awesome wu_pixel procedure by reddit u/sutaburosu
- //it was possible to render antialias dot on led matrix
- //in this example green have standart move by cells
- //but red dot have 256*resolution matrix positions and move very smoother
- #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];
- byte gHue1=0;
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- EVERY_N_MILLISECONDS(100) {gHue1++;}
- CRGB col = CHSV(0, 255, 255);
- uint32_t pos = beatsin16(30, 0, (NUM_COLS-1) * 256); //x*256
- uint32_t pos1 = beatsin16(20, 0, (NUM_ROWS-1) * 256); //y*256
- uint32_t pos2 = beatsin8(13, 0, (NUM_COLS-1)); //x*256
- uint32_t pos3 = beatsin8(19, 0, (NUM_ROWS-1) ); //y*256
- wu_pixel(pos, pos1, &col); //anialis pixel red
- leds[XY(pos2, pos3)] = CHSV (100, 255, BRIGHTNESS); //normal pixel green
- FastLED.show();
- fadeToBlackBy(leds, NUM_LEDS, 5);
- blur2d(leds, NUM_COLS, NUM_ROWS, 16);
- }
- 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) { //x and y have virtual 256 step
- // 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment