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

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 & Ein rotes Pixel läuft herum und wird dabei immer lichtschwächer &
blasser. 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.