Neue Visualisierung, Formattierung

This commit is contained in:
Peter 2019-10-04 12:44:10 +02:00
parent 6773a22498
commit 113dfd39dd
Signed by: pludi
GPG Key ID: FB1A00FEE77E2C36
3 changed files with 65 additions and 38 deletions

8
.astylerc Normal file
View File

@ -0,0 +1,8 @@
break-after-logical
indent=tab
max-code-length=72
mode=c
pad-comma
pad-header
pad-oper
style=bsd

View File

@ -3,7 +3,7 @@
#define NUM_LEDS 50
#define DATA_PIN 4
#define INTR_PIN 2
#define VIZUALIZATIONS 2
#define VIZUALIZATIONS 3
CRGB pixels[NUM_LEDS];
unsigned char offset = 0;
@ -13,12 +13,14 @@ 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);
pixels[(i + offset) % NUM_LEDS] = CRGB(128 + floor(127 * sin(
2 * 3.1415926 * i / NUM_LEDS)), 0, 0);
}
void falloffRed(unsigned char offset)
{
for (unsigned char i = 0; i < NUM_LEDS; i++)
pixels[i] = 0;
// 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);
@ -37,6 +39,14 @@ void falloffRed(unsigned char offset)
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;
@ -46,11 +56,14 @@ void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN>(pixels, NUM_LEDS);
FastLED.setBrightness(0);
for (int i = 0; i < NUM_LEDS; i++)
pixels[i] = CRGB(0, 0, 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);
}

View File

@ -45,3 +45,9 @@ Eine einfache Sinus-Funktion über eine Periode in Rot.
Ein rotes Pixel läuft herum und wird dabei immer lichtschwächer &
blasser.
### `halfSineOverlap`
3 Sinus-Halbwellen in Rot/Grün/Blau, die mit unterschiedlicher
Geschwindigkeit (1x/2x/3x) über das Band laufen und bei Überlagerung
auch entsprechend die Farben mischen.