Skip to content

Commit

Permalink
Add SetAllLeds method to Ws2812
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Oct 3, 2024
1 parent a96453b commit 6815c2b
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Ws2812 : ISpiPeripheral
/// <summary>
/// The default SPI bus speed for the device
/// </summary>
public Frequency DefaultSpiBusSpeed => new Frequency(3, Frequency.UnitType.Megahertz);
public Frequency DefaultSpiBusSpeed => new(3, Frequency.UnitType.Megahertz);

/// <summary>
/// The SPI bus speed for the device
Expand Down Expand Up @@ -79,6 +79,18 @@ public void SetLed(int index, Color color)
SetLed(index, new byte[] { color.R, color.G, color.B });
}

/// <summary>
/// Set the color of all LEDs
/// </summary>
/// <param name="color">The color</param>
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<byte> ByteToWs2812Byte(byte theByte)
{
for (int counter = 0; counter < 4; ++counter)
Expand Down

0 comments on commit 6815c2b

Please sign in to comment.