81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
#include <FastLED.h>
|
|
|
|
#define NUM_LEDS 50
|
|
#define DATA_PIN 4
|
|
#define INTR_PIN 2
|
|
#define VIZUALIZATIONS 3
|
|
|
|
CRGB pixels[NUM_LEDS];
|
|
unsigned char offset = 0;
|
|
void (*viz[VIZUALIZATIONS])(unsigned char);
|
|
volatile unsigned char currentViz = 0;
|
|
|
|
void sineRed(unsigned char offset)
|
|
{
|
|
for (unsigned char i = 0; i < NUM_LEDS; i++)
|
|
pixels[(i + offset) % NUM_LEDS] = CRGB(128 + floor(127 * sin(
|
|
2 * 3.1415926 * i / NUM_LEDS)), 0, 0);
|
|
}
|
|
void falloffRed(unsigned char offset)
|
|
{
|
|
// Alles aus
|
|
memset(pixels, 0, NUM_LEDS * sizeof(CRGB));
|
|
|
|
pixels[offset % NUM_LEDS] = CRGB(0x0F, 0xF, 0xF);
|
|
pixels[(offset + 1) % NUM_LEDS] = CRGB(0x1F, 0xE, 0xE);
|
|
pixels[(offset + 2) % NUM_LEDS] = CRGB(0x2F, 0xD, 0xD);
|
|
pixels[(offset + 3) % NUM_LEDS] = CRGB(0x3F, 0xC, 0xC);
|
|
pixels[(offset + 4) % NUM_LEDS] = CRGB(0x4F, 0xB, 0xB);
|
|
pixels[(offset + 5) % NUM_LEDS] = CRGB(0x5F, 0xA, 0xA);
|
|
pixels[(offset + 6) % NUM_LEDS] = CRGB(0x6F, 0x9, 0x9);
|
|
pixels[(offset + 7) % NUM_LEDS] = CRGB(0x7F, 0x8, 0x8);
|
|
pixels[(offset + 8) % NUM_LEDS] = CRGB(0x8F, 0x7, 0x7);
|
|
pixels[(offset + 9) % NUM_LEDS] = CRGB(0x9F, 0x6, 0x6);
|
|
pixels[(offset + 10) % NUM_LEDS] = CRGB(0xAF, 0x5, 0x5);
|
|
pixels[(offset + 11) % NUM_LEDS] = CRGB(0xBF, 0x4, 0x4);
|
|
pixels[(offset + 12) % NUM_LEDS] = CRGB(0xCF, 0x3, 0x3);
|
|
pixels[(offset + 13) % NUM_LEDS] = CRGB(0xDF, 0x2, 0x2);
|
|
pixels[(offset + 14) % NUM_LEDS] = CRGB(0xEF, 0x1, 0x1);
|
|
pixels[(offset + 15) % NUM_LEDS] = CRGB(0xFF, 0x0, 0x0);
|
|
}
|
|
|
|
void halfSineOverlap(unsigned char offset)
|
|
{
|
|
const unsigned char sine[NUM_LEDS] = {0, 87, 163, 220, 251, 251, 220, 163, 87};
|
|
for (unsigned char i = 0; i < NUM_LEDS; i++)
|
|
pixels[NUM_LEDS - i] = CRGB(sine[(i + offset) % NUM_LEDS],
|
|
sine[(i + 2 * offset) % NUM_LEDS], sine[(i + 3 * offset) % NUM_LEDS]);
|
|
}
|
|
|
|
void changeViz(void)
|
|
{
|
|
currentViz = (currentViz + 1) % VIZUALIZATIONS;
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
FastLED.addLeds<WS2812B, DATA_PIN>(pixels, NUM_LEDS);
|
|
FastLED.setBrightness(0);
|
|
// Alles aus
|
|
memset(pixels, 0, NUM_LEDS * sizeof(CRGB));
|
|
FastLED.show();
|
|
|
|
viz[0] = &sineRed;
|
|
viz[1] = &falloffRed;
|
|
viz[2] = &halfSineOverlap;
|
|
|
|
pinMode(INTR_PIN, INPUT_PULLUP);
|
|
attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
unsigned char brightness = 16 + floor(239.0 * analogRead(A0) / 1024.0);
|
|
unsigned int sleep = 100 + floor(900.0 * analogRead(A1) / 1024.0);
|
|
(*viz[currentViz])(offset);
|
|
FastLED.setBrightness(brightness);
|
|
FastLED.show();
|
|
delay(sleep);
|
|
offset++;
|
|
}
|