Change DIM LEDs

This commit is contained in:
Andreas committed 2026-04-14 14:16:10 +02:00
1 parent a6b31fe5bf
commit 0d08b06656
2 files changed
+60 -46

No files matched your search

+10 -7
View File
@@ -275,8 +275,9 @@ void setMirroredLED(int i, CRGB color) {
// Returns the thermometer gradient color for logical position i. // Returns the thermometer gradient color for logical position i.
// i = START_LED (4) → blue (cold), i = BASE_LEDS-1 (59) → red (hot). // i = START_LED (4) → blue (cold), i = BASE_LEDS-1 (59) → red (hot).
CRGB getThermometerColor(int i) { CRGB getThermometerColor(int i) {
uint8_t pos = (uint8_t)map(i, START_LED, BASE_LEDS - 1, 0, 255); // Lower half → solid blue, upper half → solid red
return blend(CRGB(0, 0, 180), CRGB(180, 0, 0), pos); 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. // Renders the thermometer state onto the LED strips.
@@ -291,13 +292,15 @@ void displayTemperature() {
if (i < START_LED) { if (i < START_LED) {
// Bottom 4 LEDs: always off // Bottom 4 LEDs: always off
color = CRGB::Black; 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 { } else {
// Inactive (dim): solid blue (lower half) or solid red (upper half)
color = getThermometerColor(i); color = getThermometerColor(i);
if (i < activeEnd) { color.nscale8(DIM_BRIGHTNESS);
color.nscale8(BRIGHT_BRIGHTNESS); // active (bright)
} else {
color.nscale8(DIM_BRIGHTNESS); // inactive (dim gradient still visible)
}
} }
setMirroredLED(i, color); setMirroredLED(i, color);
} }
+50 -39
View File
@@ -1,53 +1,64 @@
#include <FastLED.h> #include <FastLED.h>
// How many leds in your strip? #define DATA_PIN 14 // A0 used as digital out
#define NUM_LEDS 240 #define NUM_LEDS 240
#define BASE_LEDS 60 #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]; 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() { void setup() {
Serial.begin(9600); FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
Serial.println("resetting");
FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
FastLED.setBrightness(84); 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() { void loop() {
static uint8_t hue = 0; for (int s = 0; s <= NUM_SECTIONS; s++) {
Serial.print("x"); displayTemperature(s);
// First slide the led in one direction delay(1000);
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);
} }
} }