atuline

dna

May 22nd, 2020
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. /*
  2.  * By: ldirko (on Reddit)
  3.  * https://pastebin.com/pCkkkzcs
  4.  * https://old.reddit.com/user/ldirko
  5.  *
  6.  * Updated by: Preyy (on Reddit)
  7.  *
  8.  * DNA Spirals
  9.  *
  10.  * Here is a good reference from Mark Kriegsman: https://gist.github.com/kriegsman/368b316c55221134b160
  11.  *
  12.  * Full sketch demo by: Andrew Tuline
  13.  * Date: May, 2020
  14.  *
  15.  * This took far more effort than I would've expected to convert his hard coded sinuswave() function into a demo.
  16.  * For one thing, I never would've thought that FastLED's blur2D actually required that I define that XY routine.
  17.  *
  18.  * It'll probably take extra effort to make it thinner with my serpentine layout. Then, adding palettes would be nice.
  19.  *
  20.  */
  21.  
  22. #include <FastLED.h>
  23.  
  24. #define LED_PIN  2
  25. #define LED_TYPE WS2811
  26. #define COLOR_ORDER GRB
  27.  
  28. const uint8_t kMatrixWidth  = 16;
  29. const uint8_t kMatrixHeight = 16;
  30.  
  31. #define NUM_LEDS (kMatrixWidth*kMatrixHeight)
  32.  
  33. #define kMatrixSerpentineLayout true
  34.  
  35. CRGB leds[NUM_LEDS];
  36.  
  37.  
  38.  
  39.  
  40. void setup() {
  41.   delay(1000);
  42.   Serial.begin(115200);
  43.   FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS);
  44. } // setup()
  45.  
  46.  
  47.  
  48. void loop () {
  49.  
  50.   EVERY_N_MILLIS(50) {
  51.     sinuswave();
  52.     FastLED.show();
  53.   }
  54. } // loop()
  55.  
  56.  
  57.  
  58. void sinuswave() {
  59.  
  60.   uint8_t hue = 0;
  61.  
  62. #define mn 256/(kMatrixWidth*2)
  63. #define speeds 30
  64. #define freq 21
  65.  
  66.   fadeToBlackBy(leds, NUM_LEDS, 200);  
  67.  
  68. uint8_t LEDper = kMatrixHeight;
  69. uint8_t LEDstrips = kMatrixWidth;
  70.  
  71. for(int i = 0; i < kMatrixHeight; i++){
  72.     // Format: leds[coordinates oscillate between left and right with next lines out of phase] =  CHSV(base hue+difference between rows, saturation changes a little bit for variety, value varies by row)
  73.     // Increase coefficients of 'y' terms to increase the differences between rows
  74.     leds[XY(beatsin8(10, 0, kMatrixWidth-1, 0, i*4), i)] = CHSV(-hue+i*5, beatsin8(25, 200, 255, 0, i*3), beatsin8(5, 55, 255, 0, i*10));                  
  75.     leds[XY(beatsin8(10, 0, kMatrixWidth-1, 0, i*4+128), i)] = CHSV(hue+i*5+128, beatsin8(25, 200, 255, 0, i*3), beatsin8(5, 55, 255, 0, i*10+128));        // 180 degrees (128) out of phase
  76. }
  77.  
  78.   blur2d(leds, kMatrixWidth, kMatrixHeight, 16);
  79.  
  80. } // sinuswave()
  81.  
  82.  
  83. uint16_t XY( uint8_t x, uint8_t y) {            // Returns with the wiring layout.
  84.  
  85.   uint16_t i;
  86.  
  87.   if( kMatrixSerpentineLayout == false) {
  88.     i = (y * kMatrixWidth) + x;
  89.   }
  90.  
  91.   if( kMatrixSerpentineLayout == true) {
  92.     if( y & 0x01) {
  93.       uint8_t reverseX = (kMatrixWidth - 1) - x;
  94.       i = (y * kMatrixWidth) + reverseX;
  95.     } else {
  96.       i = (y * kMatrixWidth) + x;
  97.     }
  98.   }
  99.   return i;
  100.  
  101. } // XY()
Add Comment
Please, Sign In to add comment