Advertisement
ldirko

twist pattern

Aug 21st, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // twist pattern
  2. //fastled 16x16 matrix demo
  3. //Yaroslaw Turbin 21.08.2020
  4.  
  5. #include "FastLED.h"
  6.  
  7. // Matrix size
  8. #define NUM_ROWS 16
  9. #define NUM_COLS 16
  10.  
  11. // LEDs pin
  12. #define DATA_PIN 3
  13.  
  14. // LED brightness
  15. #define BRIGHTNESS 255
  16.  
  17. #define NUM_LEDS NUM_ROWS * NUM_COLS
  18.  
  19. // Define the array of leds
  20. CRGB leds[NUM_LEDS];
  21.    byte hue =0;
  22.  
  23. void setup() {
  24.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  25.   FastLED.setBrightness(BRIGHTNESS);
  26. }
  27.  
  28. void loop() {
  29.  
  30.  
  31.  
  32.   for (uint8_t i = 0; i < NUM_COLS; i+=4)    {
  33.     for (uint8_t j = 0; j < NUM_ROWS; j+=4) {
  34.    
  35.     patt1 (i,j, 128+hue+j*2, hue+i*2);
  36.     patt2 (i+2,j, 128+hue+j*2,hue+i*2);
  37.     patt2 (i,j+2, 128+hue+j*2,hue+i*2);
  38.     patt1 (i+2,j+2, 128+hue+j*2,hue+i*2);
  39.  
  40.     }}
  41.  
  42.   FastLED.delay(10);
  43.   hue +=1;
  44. }
  45.  
  46.  
  47.  
  48. uint16_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);}   
  49.  
  50.  
  51. void patt1 (uint8_t i, uint8_t j, uint8_t color1, uint8_t color2  ) {
  52.   //  leds[XY (i, j)] =  CHSV (0, 255, 0); //color of background
  53.     leds[XY (i+1, j)] =  CHSV (color1, 255, BRIGHTNESS);
  54.     leds[XY (i+1, j+1)] =  CHSV (color1, 255, BRIGHTNESS);
  55.     leds[XY (i, j+1)] =  CHSV (color2, 255, BRIGHTNESS);
  56. }
  57.  
  58. void patt2 (uint8_t i, uint8_t j, uint8_t color1, uint8_t color2) {
  59.  //   leds[XY (i, j)] =  CHSV (0, 255, 0);  //color of background
  60.     leds[XY (i+1, j)] =  CHSV (color1, 255, BRIGHTNESS);
  61.     leds[XY (i+1, j+1)] =  CHSV (color2, 255, BRIGHTNESS);
  62.     leds[XY (i, j+1)] =  CHSV (color2, 255, BRIGHTNESS);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement