Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * By: ldirko (on Reddit)
- * https://pastebin.com/pCkkkzcs
- * https://old.reddit.com/user/ldirko
- *
- * Updated by: Preyy (on Reddit)
- *
- * DNA Spirals
- *
- * Here is a good reference from Mark Kriegsman: https://gist.github.com/kriegsman/368b316c55221134b160
- *
- * Full sketch demo by: Andrew Tuline
- * Date: May, 2020
- *
- * This took far more effort than I would've expected to convert his hard coded sinuswave() function into a demo.
- * For one thing, I never would've thought that FastLED's blur2D actually required that I define that XY routine.
- *
- * It'll probably take extra effort to make it thinner with my serpentine layout. Then, adding palettes would be nice.
- *
- */
- #include <FastLED.h>
- #define LED_PIN 2
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- const uint8_t kMatrixWidth = 16;
- const uint8_t kMatrixHeight = 16;
- #define NUM_LEDS (kMatrixWidth*kMatrixHeight)
- #define kMatrixSerpentineLayout true
- CRGB leds[NUM_LEDS];
- void setup() {
- delay(1000);
- Serial.begin(115200);
- FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS);
- } // setup()
- void loop () {
- EVERY_N_MILLIS(50) {
- sinuswave();
- FastLED.show();
- }
- } // loop()
- void sinuswave() {
- uint8_t hue = 0;
- #define mn 256/(kMatrixWidth*2)
- #define speeds 30
- #define freq 21
- fadeToBlackBy(leds, NUM_LEDS, 200);
- uint8_t LEDper = kMatrixHeight;
- uint8_t LEDstrips = kMatrixWidth;
- for(int i = 0; i < kMatrixHeight; i++){
- // 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)
- // Increase coefficients of 'y' terms to increase the differences between rows
- 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));
- 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
- }
- blur2d(leds, kMatrixWidth, kMatrixHeight, 16);
- } // sinuswave()
- uint16_t XY( uint8_t x, uint8_t y) { // Returns with the wiring layout.
- uint16_t i;
- if( kMatrixSerpentineLayout == false) {
- i = (y * kMatrixWidth) + x;
- }
- if( kMatrixSerpentineLayout == true) {
- if( y & 0x01) {
- uint8_t reverseX = (kMatrixWidth - 1) - x;
- i = (y * kMatrixWidth) + reverseX;
- } else {
- i = (y * kMatrixWidth) + x;
- }
- }
- return i;
- } // XY()
Add Comment
Please, Sign In to add comment