From 6815c2b93c5bf685da71dffb811aea7f3a06e7bf Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 3 Oct 2024 11:21:24 -0700 Subject: [PATCH] Add SetAllLeds method to Ws2812 --- .../Leds.Ws2812/Driver/Ws2812.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs index 6ea0ce8db..4601162ae 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs +++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs @@ -23,7 +23,7 @@ public class Ws2812 : ISpiPeripheral /// /// The default SPI bus speed for the device /// - public Frequency DefaultSpiBusSpeed => new Frequency(3, Frequency.UnitType.Megahertz); + public Frequency DefaultSpiBusSpeed => new(3, Frequency.UnitType.Megahertz); /// /// The SPI bus speed for the device @@ -79,6 +79,18 @@ public void SetLed(int index, Color color) SetLed(index, new byte[] { color.R, color.G, color.B }); } + /// + /// Set the color of all LEDs + /// + /// The color + public void SetAllLeds(Color color) + { + for (int i = 0; i < numberOfLeds; i++) + { + SetLed(i, new byte[] { color.R, color.G, color.B }); + } + } + private static IEnumerable ByteToWs2812Byte(byte theByte) { for (int counter = 0; counter < 4; ++counter)