Skip to content

Releases: bcelary/dimmable-light

v1.7.0 - Fix getBrightness + Min Brightness (0-200 range)

08 Nov 20:02

Choose a tag to compare

Fixed

  • DimmableLightLinearized::getBrightness() now correctly tracks brightness value (was always returning 0 due to missing assignment in setBrightness())
  • Perfect round-trip precision: getBrightness() now always returns the exact value set via setBrightness()

Changed (Breaking)

  • Input range changed to 0-200 (from 0-255) for both DimmableLight and DimmableLightLinearized
    • New constant MAX_BRIGHTNESS = 200 available
    • Values >200 are automatically clamped to 200
    • 200 brightness levels sufficient for human perception

Added

  • Min brightness support with precision preservation
    • New constant MAX_MIN_BRIGHTNESS = 55 enforced (ensures 200 distinct hardware levels)
    • Input range 0-200 maps to hardware range minBrightness-255
    • Input 0 always maps to 0 (off), input 1-200 maps linearly to minBrightness-255
    • Perfect 1:1 mapping when minBrightness ≤ 55
  • New methods: getMinBrightness(), setMinBrightness()
  • All magic numbers replaced with named constants (MAX_BRIGHTNESS, MAX_MIN_BRIGHTNESS, HW_MAX)
  • Zero RAM overhead: static constexpr constants use no RAM

Migration from 1.6.x

// Old (0-255 range):
DimmableLight dimmer(5);
dimmer.setBrightness(255);  // Full brightness

// New (0-200 range):
DimmableLight dimmer(5);
dimmer.setBrightness(200);  // Full brightness
// Or use constant:
dimmer.setBrightness(DimmableLight::MAX_BRIGHTNESS);

Usage

// Create dimmer with minimum brightness 30 (prevents flickering at low levels)
DimmableLight dimmer(5, 30);  // pin 5, minBrightness=30

// Full range 0-200 now maps to hardware 0, 30-255
dimmer.setBrightness(0);    // Hardware: 0 (off)
dimmer.setBrightness(1);    // Hardware: 30
dimmer.setBrightness(100);  // Hardware: ~142
dimmer.setBrightness(200);  // Hardware: 255
uint8_t val = dimmer.getBrightness();  // Returns exact value set (perfect round-trip)

Tested

  • Example 1 (dimmable_light) compiles on megaatmega2560
  • Example 7 (linearized_dimmable_light) compiles on megaatmega2560