Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //F_lying
- //Fastled 16x16 rgb led matrix demo
- //Yaroslaw Turbin, 27.10.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //look how it look in online emulator:
- //https://wokwi.com/arduino/projects/280541577702539789
- //https://wokwi.com/arduino/projects/280607115091902988
- //or there https://editor.soulmatelights.com/gallery/434
- #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];
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- static byte hue =0;
- EVERY_N_MILLISECONDS(30) { hue++; } //30 - speed of hue change
- int x1 = beatsin8 (18, 0, (NUM_COLS-1));
- int x2 = beatsin8 (23, 0, (NUM_COLS-1));
- int y1 = beatsin8 (20, 0, (NUM_ROWS-1));
- int y2 = beatsin8 (26, 0, (NUM_ROWS-1));
- CHSV color = CHSV (hue,255,BRIGHTNESS);
- mydrawLine(x1, y1, x2, y2, color);
- blur2d (leds,NUM_COLS, NUM_ROWS, 32 );
- FastLED.show();
- } //loop
- uint16_t XY (uint8_t x, uint8_t y) {
- return (y * NUM_COLS + x);
- }
- void mydrawLine (byte x, byte y, byte x1, byte y1, CHSV color){ // my ugly line draw function )))
- byte xsteps = abs8(x-x1)+1;
- byte ysteps = abs8(y-y1)+1;
- byte steps = xsteps >= ysteps? xsteps:ysteps;
- for (byte i = 1; i <= steps; i++) {
- byte dx = lerp8by8 (x, x1, i*255/steps);
- byte dy = lerp8by8 (y, y1, i*255/steps);
- leds[XY(dx, dy)] = color; // change to += for brightness look
- }
- }
Add Comment
Please, Sign In to add comment