diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs
index 4601162ae..f9764a07e 100644
--- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs
+++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Ws2812.cs
@@ -58,13 +58,10 @@ public SpiClockConfiguration.Mode SpiBusMode
///
/// SPI bus
/// Number of leds
- /// SPI chip select port (optional)
- public Ws2812(ISpiBus spiBus, int numberOfLeds, IDigitalOutputPort? chipSelectPort = null)
+ public Ws2812(ISpiBus spiBus, int numberOfLeds)
{
- spiComms = new SpiCommunications(spiBus, chipSelectPort, spiBus.Configuration.Speed);
-
+ spiComms = new SpiCommunications(spiBus, null, DefaultSpiBusSpeed, DefaultSpiBusMode);
this.numberOfLeds = numberOfLeds;
-
// To transmit 8 bits of color we need 4 bytes and there are 3 colors
buffer = new byte[numberOfLeds * BytesPerColorPart * 3];
}
@@ -137,4 +134,4 @@ public void Show()
{
spiComms.Write(buffer);
}
-}
+}
\ No newline at end of file
diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/MeadowApp.cs
index 8d028b157..2f47c9580 100644
--- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/MeadowApp.cs
+++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/MeadowApp.cs
@@ -1,81 +1,40 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Leds;
-using Meadow.Units;
-using System;
using System.Threading.Tasks;
namespace MeadowApp
{
public class MeadowApp : App
{
- private Ws2812 _ws2812;
+ //
- private readonly int ledCount = 20;
+ private Ws2812 neoPixels;
+
+ private readonly int ledCount = 24;
public override Task Initialize()
{
- Resolver.Log.Info("Initialize");
- var _spiBus = Device.CreateSpiBus(new Frequency(3, Frequency.UnitType.Megahertz));
- _ws2812 = new Ws2812(_spiBus, ledCount);
+ var spiBus = Device.CreateSpiBus();
+ neoPixels = new Ws2812(spiBus, ledCount);
return base.Initialize();
}
public override async Task Run()
{
- Resolver.Log.Info("Run...");
-
- var rand = new Random();
-
- var colors = new Color[]
- {
- Color.Red,
- Color.Orange,
- Color.Yellow,
- Color.Green,
- Color.Blue,
- Color.Violet,
- };
-
- var c = 0;
-
while (true)
{
- var color = colors[c];
-
- Resolver.Log.Info($"Change to {color.ToString()}");
-
- _ws2812.SetLed(9, Color.Black);
- _ws2812.SetLed(8, Color.Black);
- _ws2812.SetLed(7, Color.Black);
- _ws2812.SetLed(6, Color.Black);
- _ws2812.SetLed(5, Color.Black);
- _ws2812.SetLed(4, Color.Black);
- _ws2812.SetLed(3, Color.Black);
- _ws2812.SetLed(2, Color.Black);
- _ws2812.SetLed(1, Color.Black);
- _ws2812.SetLed(0, color);
- _ws2812.Show();
- await Task.Delay(1000);
-
- _ws2812.SetLed(9, Color.Black);
- _ws2812.SetLed(8, Color.Black);
- _ws2812.SetLed(7, Color.Black);
- _ws2812.SetLed(6, Color.Black);
- _ws2812.SetLed(5, Color.Black);
- _ws2812.SetLed(4, Color.Black);
- _ws2812.SetLed(3, Color.Black);
- _ws2812.SetLed(2, Color.Black);
- _ws2812.SetLed(1, Color.Black);
- _ws2812.SetLed(0, Color.Black);
- _ws2812.Show();
-
- c++;
- if (c > 5) c = 0;
-
- await Task.Delay(1000);
+ for (int i = 0; i < neoPixels.NumberOfLeds; i++)
+ {
+ neoPixels.SetAllLeds(Color.Black);
+ neoPixels.SetLed(i, Color.Blue);
+ neoPixels.Show();
+ await Task.Delay(100);
+ }
}
}
+
+ //
}
}
\ No newline at end of file