ldirko

F_lying Fastled 16x16 rgb

Oct 27th, 2020 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //F_lying
  2. //Fastled 16x16 rgb led matrix demo
  3. //Yaroslaw Turbin, 27.10.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6.  
  7. //look how it look in online emulator:
  8. //https://wokwi.com/arduino/projects/280541577702539789
  9. //https://wokwi.com/arduino/projects/280607115091902988
  10. //or there https://editor.soulmatelights.com/gallery/434
  11.  
  12. #include "FastLED.h"
  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.  
  24. void setup() {
  25.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  26.   FastLED.setBrightness(BRIGHTNESS);
  27. }
  28.  
  29. void loop() {
  30. static byte hue =0;
  31. EVERY_N_MILLISECONDS(30) { hue++; }  //30 - speed of hue change
  32. int x1 = beatsin8 (18, 0, (NUM_COLS-1));
  33. int x2 = beatsin8 (23, 0, (NUM_COLS-1));
  34. int y1 = beatsin8 (20, 0, (NUM_ROWS-1));
  35. int y2 = beatsin8 (26, 0, (NUM_ROWS-1));
  36. CHSV color = CHSV (hue,255,BRIGHTNESS);
  37. mydrawLine(x1, y1,  x2, y2, color);
  38. blur2d (leds,NUM_COLS, NUM_ROWS, 32 );
  39. FastLED.show();
  40.  
  41. } //loop
  42.  
  43.  
  44. uint16_t XY (uint8_t x, uint8_t y) {
  45.   return (y * NUM_COLS + x);
  46. }
  47.  
  48. void mydrawLine (byte x, byte y, byte x1, byte y1, CHSV color){   // my ugly line draw function )))
  49. byte xsteps = abs8(x-x1)+1;  
  50. byte ysteps = abs8(y-y1)+1;
  51. byte steps =  xsteps >= ysteps? xsteps:ysteps;
  52.  
  53. for (byte i = 1; i <= steps; i++) {
  54. byte dx = lerp8by8 (x, x1, i*255/steps);
  55. byte dy = lerp8by8 (y, y1, i*255/steps);
  56. leds[XY(dx, dy)] = color;                               // change to += for brightness look
  57. }
  58. }
  59.  
Add Comment
Please, Sign In to add comment