Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Metaballs
- //16x16 rgb led matrix demo
- //Yaroslaw Turbin 20.07.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //some distance aproximate for get 30+ fps )))
- #include "FastLED.h"
- // Matrix size
- #define NUM_ROWS 16
- #define NUM_COLS 16
- #define NUM_LEDS (NUM_ROWS * NUM_COLS)
- // LEDs pin
- #define DATA_PIN 3
- // LED brightness
- #define BRIGHTNESS 255
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- DEFINE_GRADIENT_PALETTE( lava) {
- 0, 255, 30, 0,
- 32, 0, 0, 0,
- 128, 0, 0, 0,
- 140, 180, 180, 0,
- 255, 255, 50, 0
- };
- CRGBPalette16 myPal = lava;
- void setup() {
- Serial.begin(250000);
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- uint8_t bx1 = beatsin8(15, 0, NUM_COLS - 1, 0, 0);
- uint8_t by1 = beatsin8(18, 0, NUM_ROWS - 1, 0, 0);
- uint8_t bx2 = beatsin8(28, 0, NUM_COLS - 1, 0, 32);
- uint8_t by2 = beatsin8(23, 0, NUM_ROWS - 1, 0, 32);
- uint8_t bx3 = beatsin8(30, 0, NUM_COLS - 1, 0, 64);
- uint8_t by3 = beatsin8(24, 0, NUM_ROWS - 1, 0, 64);
- uint8_t bx4 = beatsin8(17, 0, NUM_COLS - 1, 0, 128);
- uint8_t by4 = beatsin8(25, 0, NUM_ROWS - 1, 0, 128);
- uint8_t bx5 = beatsin8(19, 0, NUM_COLS - 1, 0, 170);
- uint8_t by5 = beatsin8(21, 0, NUM_ROWS - 1, 0, 170);
- for (uint8_t i = 0; i < NUM_COLS; i++) {
- for (uint8_t j = 0; j < NUM_ROWS; j++) {
- uint16_t sum = dist(i, j, bx1, by1);
- sum = qadd8(sum, dist(i, j, bx2, by2));
- sum = qadd8(sum, dist(i, j, bx3, by3));
- sum = qadd8(sum, dist(i, j, bx4, by4));
- sum = qadd8(sum, dist(i, j, bx5, by5));
- // byte col = constrain(120 * sum, 128, 255);
- leds[XY (i, j)] = ColorFromPalette(myPal, constrain(sum, 128, 255), BRIGHTNESS);
- //Serial.println(col);
- }
- }
- FastLED.show();
- static int frame = 0;
- if (frame++ % 32 == 0)
- Serial.println(FastLED.getFPS());
- } //loop
- uint16_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);} //simple function to find led number in led matrix,
- byte dist (uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { // https://gamedev.ru/tip/?id=41
- byte dx= abs8(y2-y1);
- byte dy = abs8(x2-x1);
- if ( dx < dy ) return 200/dy;
- else return 200/dx;
- }
Add Comment
Please, Sign In to add comment