Helligkeit/Geschwindigkeit steuerbar

- Potis auf A0/A1 können Helligkeit/Geschwindigkeit steuern
- README entsprechend aktualisiert
- Code neu formattiert
This commit is contained in:
Peter 2019-10-02 13:17:47 +02:00
parent 96dae72d04
commit 6773a22498
Signed by: pludi
GPG key ID: FB1A00FEE77E2C36
2 changed files with 53 additions and 39 deletions

View file

@ -10,50 +10,58 @@ unsigned char offset = 0;
void (*viz[VIZUALIZATIONS])(unsigned char); void (*viz[VIZUALIZATIONS])(unsigned char);
volatile unsigned char currentViz = 0; volatile unsigned char currentViz = 0;
void sineRed(unsigned char offset) { 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); 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) { void falloffRed(unsigned char offset)
for (unsigned char i = 0; i < NUM_LEDS; i++) {
pixels[i] = 0; for (unsigned char i = 0; i < NUM_LEDS; i++)
pixels[offset % NUM_LEDS] = CRGB(0x0F, 0xF, 0xF); pixels[i] = 0;
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 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.setBrightness(255); FastLED.addLeds<WS2812B, DATA_PIN>(pixels, NUM_LEDS);
for (int i = 0; i < NUM_LEDS; i++) FastLED.setBrightness(0);
pixels[i] = CRGB(0, 0, 0); for (int i = 0; i < NUM_LEDS; i++)
FastLED.show(); pixels[i] = CRGB(0, 0, 0);
viz[0] = &sineRed; FastLED.show();
viz[1] = &falloffRed; viz[0] = &sineRed;
pinMode(INTR_PIN, INPUT_PULLUP); viz[1] = &falloffRed;
attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING); pinMode(INTR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING);
} }
void loop() { void loop()
(*viz[currentViz])(offset); {
FastLED.show(); unsigned char brightness = 16 + floor(239.0 * analogRead(A0) / 1024.0);
delay(100); unsigned int sleep = 100 + floor(900.0 * analogRead(A1) / 1024.0);
offset++; (*viz[currentViz])(offset);
FastLED.setBrightness(brightness);
FastLED.show();
delay(sleep);
offset++;
} }

View file

@ -9,12 +9,18 @@ Specs
- Arduino UNO - Arduino UNO
- Data Pin: 4 - Data Pin: 4
- Interrupt Pin: 2 - Interrupt Pin: 2
- Helligkeit: Potentiometer auf Pin A0
- Geschwindigkeit: Potentiometer auf Pin A1
- LED Strip: - LED Strip:
- 5m lang - 5m lang
- 10 Pixel/m - 10 Pixel/m
- 3 RGB-LEDs/Pixel - 3 RGB-LEDs/Pixel
- WS2818B Controller - WS2818B Controller
Die Potentiometer auf Pins A0 und A1 steuern die Helligkeit (zwischen
1/16-tel und voll) bzw. Geschwindigkeit (zwischen 100ms und 1000ms
zwischen den Schritten) der Animation.
Code Code
---- ----