Change animation

This commit is contained in:
Andreas committed 2026-04-14 13:38:38 +02:00
1 parent 8bb65dafc2
commit 011a4171cc
1 file changed
+22 -18
+22 -18
View File
@@ -170,10 +170,24 @@ void onButtonPressed(int buttonIdx) {
Serial.println(); Serial.println();
// --- END DEBUG --- // --- END DEBUG ---
// For a re-press (no temperature change), shift the animation window by one
// section so it still plays meaningfully:
// correct re-press → show the section just above current level in green, then remove
// wrong/half re-press → show the topmost active section rising in red/yellow
int animFrom = prevTemp;
int animTo = tempSections;
if (prevTemp == tempSections) {
if (type == ANSWER_CORRECT) {
animFrom = constrain(tempSections + 1, 0, NUM_SECTIONS);
} else {
animFrom = constrain(tempSections - 1, 0, NUM_SECTIONS);
}
}
switch (type) { switch (type) {
case ANSWER_CORRECT: playTempAnimation(prevTemp, tempSections, CRGB(0, 180, 0)); break; case ANSWER_CORRECT: playTempAnimation(animFrom, animTo, CRGB(0, 180, 0)); break;
case ANSWER_HALF: playTempAnimation(prevTemp, tempSections, CRGB(255, 180, 0)); break; case ANSWER_HALF: playTempAnimation(animFrom, animTo, CRGB(255, 180, 0)); break;
case ANSWER_WRONG: playTempAnimation(prevTemp, tempSections, CRGB(180, 0, 0)); break; case ANSWER_WRONG: playTempAnimation(animFrom, animTo, CRGB(180, 0, 0)); break;
} }
displayTemperature(); displayTemperature();
@@ -294,12 +308,12 @@ void displayTemperature() {
// ===================== ANSWER FEEDBACK ANIMATIONS ===================== // ===================== ANSWER FEEDBACK ANIMATIONS =====================
// Feedback animation for a button press. // Feedback animation for a button press.
// fromSections = temp before, toSections = temp after. // fromSections = animation start, toSections = animation end.
// //
// Correct (drop): all affected LEDs appear instantly in color, then vanish top→bottom. // Drop (toSections < fromSections): all LEDs in range appear in color instantly,
// Wrong/half (rise): LEDs added one by one bottom→top in color, then stay put // then vanish one by one top→bottom (used for correct answers).
// (displayTemperature() corrects colors immediately after). // Rise (toSections > fromSections): LEDs added one by one bottom→top in color
// Re-press (no change): section at boundary flashes instantly, then restores. // (used for wrong/half answers). displayTemperature() fixes colors afterwards.
void playTempAnimation(int fromSections, int toSections, CRGB color) { void playTempAnimation(int fromSections, int toSections, CRGB color) {
if (toSections < fromSections) { if (toSections < fromSections) {
// ---- CORRECT: temperature drops ---- // ---- CORRECT: temperature drops ----
@@ -332,16 +346,6 @@ void playTempAnimation(int fromSections, int toSections, CRGB color) {
delay(60); delay(60);
} }
delay(150); delay(150);
} else {
// ---- RE-PRESS: no temperature change ----
int section = constrain(fromSections, 0, NUM_SECTIONS - 1);
int ledStart = START_LED + section * LEDS_PER_SECTION;
int ledEnd = ledStart + LEDS_PER_SECTION;
for (int led = ledStart; led < ledEnd; led++) setMirroredLED(led, color);
FastLED.show();
delay(300);
} }
} }