From 92967e06184dcef034810689bc875899bd8a7f28 Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Fri, 29 Sep 2023 09:43:58 -0400 Subject: [PATCH] drivers/led/neopixel: Also clamp constructor brightness Signed-off-by: Tom Mount --- micropython/drivers/led/neopixel/neopixel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/drivers/led/neopixel/neopixel.py b/micropython/drivers/led/neopixel/neopixel.py index 6325b438..409d9183 100644 --- a/micropython/drivers/led/neopixel/neopixel.py +++ b/micropython/drivers/led/neopixel/neopixel.py @@ -12,7 +12,7 @@ class NeoPixel: self.pin = pin self.n = n self.bpp = bpp - self.brightness = brightness + self.brightness = min(max(brightness, 0.0), 1.0) self.buf = bytearray(n * bpp) self.pin.init(pin.OUT) # Timing arg can either be 1 for 800kHz or 0 for 400kHz, @@ -45,7 +45,7 @@ class NeoPixel: def set_brightness(self, b: float): self.brightness = min(max(b, 0.0), 1.0) - for i in range(self.n) + for i in range(self.n): self[i] = self[i] def write(self):