//source: https://editor.soulmatelights.com/gallery/512-dna-spiral-variation
#include "FastLED.h"
#define DATA_PIN 2
#define BRIGHTNESS 255
#define NUM_LEDS 256
#define LED_COLS 16
#define LED_ROWS 16
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
//#define FRAMES_PER_SECOND 60
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
const bool kMatrixSerpentineLayout = false;
#define speeds 50 // speed of rotation
#define freq 6 //change this will made spiral big or small
void setup() {
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS); //setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
//Serial.begin(115200);
}
void loop()
{
static byte hue = 0;
int ms = millis() / 10;
nscale8(leds, NUM_LEDS, 120);
for (int i = 0; i < LED_ROWS; i++) {
int x = beatsin8(speeds, 0, LED_ROWS - 1, 0, i * freq) + beatsin8(speeds - 7, 0, LED_ROWS - 1, 0, i * freq + 128);
int x1 = beatsin8(speeds, 0, LED_ROWS - 1, 0, 128 + i * freq) + beatsin8(speeds - 7, 0, LED_ROWS - 1, 0, 128 + 64 + i * freq);
hue = i * 128 / (LED_ROWS - 1) + ms;
CRGB color = CHSV(hue, 255, 255);
if ((i + ms / 8) & 3) mydrawLine(x / 2, x1 / 2, i, color, 1, 1);
}
FastLED.show();
}
void mydrawLine(byte x, byte x1, byte y, CRGB color, bool dot, bool grad) { // my ugly hori line draw function )))
byte steps = abs8(x - x1) + 1;
for (byte i = 1; i <= steps; i++) {
byte dx = lerp8by8(x, x1, i * 255 / steps);
int index = XY(dx, y);
leds[index] += color; // change to += for brightness look
if (grad) leds[index] %= (i * 255 / steps); //for draw gradient line
}
if (dot) { //add white point at the ends of line
leds[XY(x, y)] += CRGB::DarkSlateGray;
leds[XY(x1, y)] += CRGB::White;
}
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}