//Hipnotic_RGB
//241 LED ring cilindrical map
//Fastled rgb led demo
//Yaroslaw Turbin, 25-03-2021
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//https://twitter.com/ldir_ko
#include <FastLED.h>
#define DATA_PIN 3
#define LED_COLS 16 // resolution for cilindrical lookup table
#define LED_ROWS 16 // resolution for cinindrical lookup table
#define NUM_LEDS 256
#define LED_TYPE WS2812B //leds type
#define COLOR_ORDER GRB //color order of leds
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS+1]; //one safe pixel in bottom. its index 2410
#define petals 6
bool setupm = 1;
const uint8_t C_X = LED_COLS / 2;
const uint8_t C_Y = LED_ROWS / 2;
const uint8_t mapp = 255 / LED_COLS;
struct{
uint8_t angle;
uint8_t radius;
} rMap[LED_COLS][LED_ROWS];
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection( TypicalLEDStrip );
FastLED.clear();
}
void loop() {
static byte speed = 2;
LEDS.show();
//+++++++++++++++++++++++++++
// FastLED.clear();
if (setupm) {
setupm = 0;
for (int8_t x = -C_X; x < C_X + (LED_COLS % 2); x++) {
for (int8_t y = -C_Y; y < C_Y + (LED_ROWS % 2); y++) {
rMap[x + C_X][y + C_Y].angle = 128 * (atan2(y, x) / PI);
rMap[x + C_X][y + C_Y].radius = hypot(x, y) * mapp; //thanks Sutaburosu
}
}
}
static uint32_t t;
t += speed;
for (uint8_t x = 0; x < LED_COLS; x++) {
for (uint8_t y = 0; y < LED_ROWS; y++) {
byte angle = rMap[x][y].angle;
byte radius = rMap[x][y].radius;
leds[XY(x, y)] = CHSV(255,181,sin8(t-radius+sin8(t - angle*petals)/5));
}
}
delay(20);
//+++++++++++++++++++++++++
}
uint16_t XY (uint8_t x, uint8_t y) { return (y * LED_COLS + x);}