From 4d312050332da9cd2547d4a87e76560e04d14136 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 7 Feb 2018 00:40:06 +0100 Subject: [PATCH] more led handling --- src/hardware.h | 2 +- src/led.cpp | 25 ++++--------------------- src/led.h | 5 ++--- src/screen.cpp | 8 +++++++- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/hardware.h b/src/hardware.h index d8ed6a9..dc5b951 100644 --- a/src/hardware.h +++ b/src/hardware.h @@ -10,7 +10,7 @@ static constexpr uint8_t rotaryPinA = 39; static constexpr uint8_t rotaryPinB = 38; static constexpr uint8_t rotaryPinButton = 17; static constexpr uint8_t PROGMEM LED_PIN = 21; -static constexpr uint8_t PROGMEM NUM_LEDS = 21; +static constexpr uint8_t PROGMEM NUM_LEDS = 10; #define LED_TYPE WS2812B #define COLOR_ORDER GRB static constexpr uint8_t ext_wakeup_pin_1 = 0; diff --git a/src/led.cpp b/src/led.cpp index c12dd0d..825ed8d 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -22,29 +22,13 @@ void Led::loop_confetti(void) fadeToBlackBy( leds, NUM_LEDS, 10); int pos = random16(NUM_LEDS); leds[pos] += CHSV( index + random8(64), 200, 255); - - leds[0] = CRGB::White; - leds[1] = CRGB::White; - leds[NUM_LEDS-1] = CRGB::White; - leds[NUM_LEDS-2] = CRGB::White; - leds[NUM_LEDS-3] = CRGB::White; } -void Led::loop_dispense(void) { - // top: led 9 and 10 - +void Led::loop_sweep(void) { // a colored dot sweeping back and forth, with fading trails fadeToBlackBy( leds, NUM_LEDS, 20); int pos = beatsin16( 13, 0, NUM_LEDS-1 ); leds[pos] += CHSV( index, 255, 192); - - leds[0] = CRGB::White; - leds[NUM_LEDS-1] = CRGB::White; - leds[NUM_LEDS-2] = CRGB::White; -} - -void Led::loop_denied(void) { - fill_solid(leds, NUM_LEDS, CRGB::Red); } void Led::loop_steady(void) { @@ -54,17 +38,16 @@ void Led::loop_steady(void) { void Led::changeAnimation(uint8_t num, uint16_t duration) { if (duration == 0) this->duration = UINT16_MAX; else this->duration = duration; - if (num == 0) refresh = &Led::loop_steady; - else if (num == 1) refresh = &Led::loop_dispense; + if (num == 0) refresh = &Led::loop_steady; + else if (num == 1) refresh = &Led::loop_sweep; else if (num == 2) refresh = &Led::loop_confetti; else if (num == 3) refresh = &Led::loop_rainbow; - else if (num == 4) refresh = &Led::loop_denied; } void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) { color = CRGB(r, g, b); } -void Led::changeBrightness(uint8_t brightness) { +void Led::setBrightness(uint8_t brightness) { if (brightness > 254) { // don't set first byte to 255 on tm1829 FastLED.setBrightness(254); } else { diff --git a/src/led.h b/src/led.h index 4a0b642..5ec0d5e 100644 --- a/src/led.h +++ b/src/led.h @@ -14,7 +14,7 @@ class Led { void setup(void); void changeAnimation(uint8_t num, uint16_t duration); void changeColor(uint8_t, uint8_t, uint8_t); - void changeBrightness(uint8_t); + void setBrightness(uint8_t); private: CRGB leds[NUM_LEDS]; void animationTask(void*); @@ -24,8 +24,7 @@ class Led { void loop_steady(void); void loop_rainbow(void); void loop_confetti(void); - void loop_dispense(void); - void loop_denied(void); + void loop_sweep(void); uint16_t duration; uint8_t index; CRGB color; diff --git a/src/screen.cpp b/src/screen.cpp index 71c2aea..180b8b3 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -112,6 +112,7 @@ StationMenu::StationMenu() { "Live Ireland", "Ye Ol Celtic Pub", "Gone Country - NZCMR", + "Radio Essen", "xd0.de MPD", "\xAB Return"}; } @@ -149,9 +150,12 @@ uint8_t StationMenu::select() { mp3.start("http://192.99.41.102:5044/stream"); break; case 10: - mp3.start("http://172.16.75.17:8000/mopidy"); + mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); break; case 11: + mp3.start("http://172.16.75.17:8000/mopidy"); + break; + case 12: menuChange = eMainMenu; return current_pos; break; @@ -254,6 +258,7 @@ void MainScreen::next() { if (volume < 100) volume++; lastVolumeChange = millis(); mp3.setVolume(volume); + led.setBrightness((255*volume)/100); Serial.printf("volume: %d\n", volume); } @@ -261,5 +266,6 @@ void MainScreen::previous() { if (volume > 0) volume--; lastVolumeChange = millis(); mp3.setVolume(volume); + led.setBrightness((255*volume)/100); Serial.printf("volume: %d\n", volume); }