From 0d08b06656680e64ad2d916537c814f2984174c1 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Tue, 14 Apr 2026 14:16:10 +0200 Subject: [PATCH] Change DIM LEDs --- ExploringUncertanties.ino | 17 ++++--- LEDStrip/test/test.ino | 93 ++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/ExploringUncertanties.ino b/ExploringUncertanties.ino index e5cba5a..5ebb97b 100644 --- a/ExploringUncertanties.ino +++ b/ExploringUncertanties.ino @@ -275,8 +275,9 @@ void setMirroredLED(int i, CRGB color) { // Returns the thermometer gradient color for logical position i. // i = START_LED (4) → blue (cold), i = BASE_LEDS-1 (59) → red (hot). CRGB getThermometerColor(int i) { - uint8_t pos = (uint8_t)map(i, START_LED, BASE_LEDS - 1, 0, 255); - return blend(CRGB(0, 0, 180), CRGB(180, 0, 0), pos); + // Lower half → solid blue, upper half → solid red + int midpoint = START_LED + ACTIVE_LEDS / 2; // LED 32 + return (i < midpoint) ? CRGB(0, 0, 180) : CRGB(180, 0, 0); } // Renders the thermometer state onto the LED strips. @@ -291,13 +292,15 @@ void displayTemperature() { if (i < START_LED) { // Bottom 4 LEDs: always off color = CRGB::Black; + } else if (i < activeEnd) { + // Active (bright): blue→red gradient + uint8_t pos = (uint8_t)map(i, START_LED, BASE_LEDS - 1, 0, 255); + color = blend(CRGB(0, 0, 180), CRGB(180, 0, 0), pos); + color.nscale8(BRIGHT_BRIGHTNESS); } else { + // Inactive (dim): solid blue (lower half) or solid red (upper half) color = getThermometerColor(i); - if (i < activeEnd) { - color.nscale8(BRIGHT_BRIGHTNESS); // active (bright) - } else { - color.nscale8(DIM_BRIGHTNESS); // inactive (dim gradient still visible) - } + color.nscale8(DIM_BRIGHTNESS); } setMirroredLED(i, color); } diff --git a/LEDStrip/test/test.ino b/LEDStrip/test/test.ino index 02277b8..86b5ca8 100644 --- a/LEDStrip/test/test.ino +++ b/LEDStrip/test/test.ino @@ -1,53 +1,64 @@ #include -// How many leds in your strip? -#define NUM_LEDS 240 -#define BASE_LEDS 60 +#define DATA_PIN 14 // A0 used as digital out +#define NUM_LEDS 240 +#define BASE_LEDS 60 -// For led chips like Neopixels, which have a data line, ground, and power, you just -// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, -// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN -#define DATA_PIN 14 -#define CLOCK_PIN 13 - -// Define the array of leds CRGB leds[NUM_LEDS]; +// Thermometer layout — must match ExploringUncertanties.ino +const int NUM_SECTIONS = 8; +const int LEDS_PER_SECTION = 7; +const int ACTIVE_LEDS = NUM_SECTIONS * LEDS_PER_SECTION; // 56 +const int START_LED = BASE_LEDS - ACTIVE_LEDS; // 4 + +const uint8_t DIM_BRIGHTNESS = 12; +const uint8_t BRIGHT_BRIGHTNESS = 200; + +void setMirroredLED(int i, CRGB color) { + if (i < 0 || i >= BASE_LEDS) return; + leds[i] = color; + leds[119 - i] = color; + leds[120 + i] = color; + leds[239 - i] = color; +} + +CRGB getThermometerColor(int i) { + // Lower half → solid blue, upper half → solid red + int midpoint = START_LED + ACTIVE_LEDS / 2; // LED 32 + return (i < midpoint) ? CRGB(0, 0, 180) : CRGB(180, 0, 0); +} + +void displayTemperature(int sections) { + int activeEnd = START_LED + sections * LEDS_PER_SECTION; + + for (int i = 0; i < BASE_LEDS; i++) { + CRGB color; + if (i < START_LED) { + color = CRGB::Black; + } else if (i < activeEnd) { + // Active (bright): blue→red gradient + uint8_t pos = (uint8_t)map(i, START_LED, BASE_LEDS - 1, 0, 255); + color = blend(CRGB(0, 0, 180), CRGB(180, 0, 0), pos); + color.nscale8(BRIGHT_BRIGHTNESS); + } else { + // Inactive (dim): solid blue (lower half) or solid red (upper half) + color = getThermometerColor(i); + color.nscale8(DIM_BRIGHTNESS); + } + setMirroredLED(i, color); + } + FastLED.show(); +} + void setup() { - Serial.begin(9600); - Serial.println("resetting"); - FastLED.addLeds(leds,NUM_LEDS); + FastLED.addLeds(leds, NUM_LEDS); FastLED.setBrightness(84); } -// Sets LED i and all its mirrored positions: -// i, 120-i, 120+i, 180-i, 180+i -void setMirroredLED(int i, CHSV color) { - leds[i] = color; - if (120 - i >= 0 && 120 - i < NUM_LEDS) leds[119 - i] = color; - if (120 + i < NUM_LEDS) leds[120 + i] = color; - if (239 - i >= 0 && 239 - i < NUM_LEDS) leds[239 - i] = color; -} - -void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } } - void loop() { - static uint8_t hue = 0; - Serial.print("x"); - // First slide the led in one direction - for(int i = 0; i < BASE_LEDS; i++) { - setMirroredLED(i, CHSV(hue++, 255, 255)); - FastLED.show(); - fadeall(); - delay(10); - } - Serial.print("x"); - - // Now go in the other direction. - for(int i = (BASE_LEDS)-1; i >= 0; i--) { - setMirroredLED(i, CHSV(hue++, 255, 255)); - FastLED.show(); - fadeall(); - delay(10); + for (int s = 0; s <= NUM_SECTIONS; s++) { + displayTemperature(s); + delay(1000); } }