From 9b5be62585fabd3e9c6cf6b072cfb49c7f0abc8d Mon Sep 17 00:00:00 2001 From: Tom Mount Date: Fri, 6 Oct 2023 11:52:27 -0400 Subject: [PATCH] drivers/led/neopixel: Add tests for new features. Signed-off-by: Tom Mount --- .../drivers/led/neopixel/neopixel_test.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 micropython/drivers/led/neopixel/neopixel_test.py diff --git a/micropython/drivers/led/neopixel/neopixel_test.py b/micropython/drivers/led/neopixel/neopixel_test.py new file mode 100644 index 00000000..55902646 --- /dev/null +++ b/micropython/drivers/led/neopixel/neopixel_test.py @@ -0,0 +1,32 @@ +import machine +import neopixel + + +def neopixel_test(): + np = neopixel.NeoPixel(machine.Pin(1), 3) + print("Fill with a color.") + np.fill((255, 128, 64)) + print("Verify the bytes to be written") + expected_bytearray = bytearray([255, 128, 64, 255, 128, 64, 255, 128, 64]) + actual_bytearray = np.buf + print( + f'Initial fill: {"passed" if expected_bytearray == actual_bytearray else "failed"}.' + ) + print() + + print("Change brightness of all pixels.") + np.brightness(0.5) + expected_bytearray = bytearray([127, 64, 32, 127, 64, 32, 127, 64, 32]) + actual_bytearray = np.buf + print( + f'Brightness change: {"passed" if expected_bytearray == actual_bytearray else "failed"}.' + ) + print() + + print("Get current brightness.") + expected_brightness = 0.5 + actual_brightness = np.brightness() + print( + f'Brightness get: {"passed" if expected_brightness == actual_brightness else "failed"}.' + ) + print()