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,11 +10,13 @@ unsigned char offset = 0;
void (*viz[VIZUALIZATIONS])(unsigned char);
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);
}
void falloffRed(unsigned char offset) {
void falloffRed(unsigned char offset)
{
for (unsigned char i = 0; i < NUM_LEDS; i++)
pixels[i] = 0;
pixels[offset % NUM_LEDS] = CRGB(0x0F, 0xF, 0xF);
@ -35,13 +37,15 @@ void falloffRed(unsigned char offset) {
pixels[(offset + 15) % NUM_LEDS] = CRGB(0xFF, 0x0, 0x0);
}
void changeViz(void) {
void changeViz(void)
{
currentViz = (currentViz + 1) % VIZUALIZATIONS;
}
void setup() {
void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN>(pixels, NUM_LEDS);
FastLED.setBrightness(255);
FastLED.setBrightness(0);
for (int i = 0; i < NUM_LEDS; i++)
pixels[i] = CRGB(0, 0, 0);
FastLED.show();
@ -51,9 +55,13 @@ void setup() {
attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING);
}
void loop() {
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(100);
delay(sleep);
offset++;
}

View file

@ -9,12 +9,18 @@ Specs
- Arduino UNO
- Data Pin: 4
- Interrupt Pin: 2
- Helligkeit: Potentiometer auf Pin A0
- Geschwindigkeit: Potentiometer auf Pin A1
- LED Strip:
- 5m lang
- 10 Pixel/m
- 3 RGB-LEDs/Pixel
- 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
----