-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1079 from WildernessLabs/ws28212_hackin
WS2812 driver cleanup
- Loading branch information
Showing
2 changed files
with
18 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 15 additions & 56 deletions
71
Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/MeadowApp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<F7FeatherV2> | ||
{ | ||
private Ws2812 _ws2812; | ||
//<!=SNIP=> | ||
|
||
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); | ||
} | ||
} | ||
} | ||
|
||
//<!=SNOP=> | ||
} | ||
} |