diff --git a/ExploringUncertanties.ino b/ExploringUncertanties.ino index a3df2cb..e5cba5a 100644 --- a/ExploringUncertanties.ino +++ b/ExploringUncertanties.ino @@ -170,10 +170,24 @@ void onButtonPressed(int buttonIdx) { Serial.println(); // --- 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) { - case ANSWER_CORRECT: playTempAnimation(prevTemp, tempSections, CRGB(0, 180, 0)); break; - case ANSWER_HALF: playTempAnimation(prevTemp, tempSections, CRGB(255, 180, 0)); break; - case ANSWER_WRONG: playTempAnimation(prevTemp, tempSections, CRGB(180, 0, 0)); break; + case ANSWER_CORRECT: playTempAnimation(animFrom, animTo, CRGB(0, 180, 0)); break; + case ANSWER_HALF: playTempAnimation(animFrom, animTo, CRGB(255, 180, 0)); break; + case ANSWER_WRONG: playTempAnimation(animFrom, animTo, CRGB(180, 0, 0)); break; } displayTemperature(); @@ -294,12 +308,12 @@ void displayTemperature() { // ===================== ANSWER FEEDBACK ANIMATIONS ===================== // 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. -// Wrong/half (rise): LEDs added one by one bottom→top in color, then stay put -// (displayTemperature() corrects colors immediately after). -// Re-press (no change): section at boundary flashes instantly, then restores. +// Drop (toSections < fromSections): all LEDs in range appear in color instantly, +// then vanish one by one top→bottom (used for correct answers). +// Rise (toSections > fromSections): LEDs added one by one bottom→top in color +// (used for wrong/half answers). displayTemperature() fixes colors afterwards. void playTempAnimation(int fromSections, int toSections, CRGB color) { if (toSections < fromSections) { // ---- CORRECT: temperature drops ---- @@ -332,16 +346,6 @@ void playTempAnimation(int fromSections, int toSections, CRGB color) { delay(60); } 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); } }