Skip to content

Commit db674ce

Browse files
authored
Adjusting for Ws8xxx and Sk6812 drivers, adding Fire led bar (#131)
1 parent ac613a2 commit db674ce

24 files changed

+193
-252
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,25 +372,33 @@ M5StickC.Led.Toggle();
372372

373373
The M5StickC/CPlus and Atom Lite/Matrix exposes an infrared led. You can access it thru the `InfraredLed` property. This will give you a `TransmitterChannel`. Check out the [sample pack](https://github.com/nanoframework/Samples/tree/main/samples/Hardware.Esp32.Rmt) to understand how to use it.
374374

375-
### NeoPixel
375+
### NeoPixel on AtomLite
376376

377377
The Atom Lite exposes a rgb led. You can access it thru the `NeoPixel` property:
378378

379379
```csharp
380380
// This will set NeoPixel to green:
381-
AtomLite.NeoPixel.SetColor(Color.Green);
381+
AtomLite.NeoPixel.Image.SetPixel(0, 0, Color.Green);
382+
AtomLite.NeoPixel.Update();
382383
```
383384

384-
### RGB LED matrix
385+
### RGB LED matrix on AtomMatrix and Led bar on Fire
385386

386387
The Atom Matrix has a matrix of 25 RGB LEDs.
387388
The position of the LEDs in the array follows their placement in the matrix, being 0 the one at the top left corner, growing left to right, top to bottom.
388389

389-
You can access it thru the `LedMatrix` property, like this:
390+
You can access it thru the `LedMatrix` property on the AtomMatrix, like this:
390391

391392
```csharp
392-
// This will set the RGB LED at position 0 to green
393-
AtomMatrix.LedMatrix.SetColor(0, Color.Green);
393+
// This will set the RGB LED at position 2, 2 to green
394+
AtomMatrix.LedMatrix.Image.SetPixel(2, 2, Color.Green);
395+
```
396+
397+
Similarly, you have access to the `LedBar` property on the Fire:
398+
399+
```csharp
400+
// This will set the second RGB LED to green
401+
Fire.LedBar.Image.SetPixel(2, 0, Color.Green);
394402
```
395403

396404
After you're done with updating all the LEDs that you want to change, flush the updated to the LEDs, like this:
@@ -400,6 +408,13 @@ After you're done with updating all the LEDs that you want to change, flush the
400408
AtomMatrix.LedMatrix.Update();
401409
```
402410

411+
And on the Fire:
412+
413+
```csharp
414+
// This will update all RGB LED
415+
Fire.LedBar.Update();
416+
```
417+
403418
## Feedback and documentation
404419

405420
For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).

Tests/AtomLiteTestApp/AtomLiteTestApp.nfproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@
2929
<HintPath>..\..\packages\nanoFramework.Iot.Device.Button.1.0.300\lib\Iot.Device.Button.dll</HintPath>
3030
<Private>True</Private>
3131
</Reference>
32+
<Reference Include="Iot.Device.Ws28xx.Esp32">
33+
<HintPath>..\..\packages\nanoFramework.Iot.Device.Ws28xx.Esp32.1.0.300\lib\Iot.Device.Ws28xx.Esp32.dll</HintPath>
34+
</Reference>
3235
<Reference Include="mscorlib, Version=1.12.0.4, Culture=neutral, PublicKeyToken=c07d481e9758c731">
3336
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.12.0\lib\mscorlib.dll</HintPath>
3437
<Private>True</Private>
3538
</Reference>
39+
<Reference Include="nanoFramework.Hardware.Esp32.Rmt">
40+
<HintPath>..\..\packages\nanoFramework.Hardware.Esp32.Rmt.1.2.2\lib\nanoFramework.Hardware.Esp32.Rmt.dll</HintPath>
41+
</Reference>
3642
<Reference Include="nanoFramework.Runtime.Events, Version=1.10.0.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
3743
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.10.0\lib\nanoFramework.Runtime.Events.dll</HintPath>
3844
<Private>True</Private>

Tests/AtomLiteTestApp/Program.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static void Main()
1515
{
1616
var button = AtomLite.Button;
1717
var rgb = AtomLite.NeoPixel;
18-
rgb.SetColor(Color.FromArgb(255, 255, 0, 0));
18+
rgb.Image.SetPixel(0, 0, Color.FromArgb(255, 255, 0, 0));
19+
rgb.Update();
1920

2021
button.Press += Button_Press;
2122

@@ -26,19 +27,22 @@ public static void Main()
2627

2728
private static void Button_Press(object sender, EventArgs e)
2829
{
29-
var color = AtomLite.NeoPixel.GetColor();
30-
if(color.R > 0)
30+
var color = AtomLite.NeoPixel.Image.Data;
31+
// Coded as G, R, B
32+
if (color[1] > 0)
3133
{
32-
AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 255, 0));
34+
AtomLite.NeoPixel.Image.SetPixel(0, 0, Color.FromArgb(255, 0, 255, 0));
3335
}
34-
else if (color.G > 0)
36+
else if (color[0] > 0)
3537
{
36-
AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 0, 255));
38+
AtomLite.NeoPixel.Image.SetPixel(0, 0, Color.FromArgb(255, 0, 0, 255));
3739
}
3840
else
3941
{
40-
AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 255, 0, 0));
42+
AtomLite.NeoPixel.Image.SetPixel(0, 0, Color.FromArgb(255, 255, 0, 0));
4143
}
44+
45+
AtomLite.NeoPixel.Update();
4246
}
4347
}
4448
}

Tests/AtomLiteTestApp/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" />
4+
<package id="nanoFramework.Hardware.Esp32.Rmt" version="1.2.2" targetFramework="netnanoframework10" />
45
<package id="nanoFramework.Iot.Device.Button" version="1.0.300" targetFramework="netnanoframework10" />
6+
<package id="nanoFramework.Iot.Device.Ws28xx.Esp32" version="1.0.300" targetFramework="netnanoframework10" />
57
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
68
<package id="nanoFramework.System.Device.Gpio" version="1.0.4" targetFramework="netnanoframework10" />
79
<package id="nanoFramework.System.Drawing" version="1.0.289" targetFramework="netnanoframework10" />

Tests/AtomMatrixTestApp/AtomMatrixTestApp.nfproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@
2929
<HintPath>..\..\packages\nanoFramework.Iot.Device.Button.1.0.300\lib\Iot.Device.Button.dll</HintPath>
3030
<Private>True</Private>
3131
</Reference>
32+
<Reference Include="Iot.Device.Ws28xx.Esp32">
33+
<HintPath>..\..\packages\nanoFramework.Iot.Device.Ws28xx.Esp32.1.0.300\lib\Iot.Device.Ws28xx.Esp32.dll</HintPath>
34+
</Reference>
3235
<Reference Include="mscorlib, Version=1.12.0.4, Culture=neutral, PublicKeyToken=c07d481e9758c731">
3336
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.12.0\lib\mscorlib.dll</HintPath>
3437
<Private>True</Private>
3538
</Reference>
39+
<Reference Include="nanoFramework.Hardware.Esp32.Rmt">
40+
<HintPath>..\..\packages\nanoFramework.Hardware.Esp32.Rmt.1.2.2\lib\nanoFramework.Hardware.Esp32.Rmt.dll</HintPath>
41+
</Reference>
3642
<Reference Include="nanoFramework.Runtime.Events, Version=1.10.0.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
3743
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.10.0\lib\nanoFramework.Runtime.Events.dll</HintPath>
3844
<Private>True</Private>

Tests/AtomMatrixTestApp/Program.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Iot.Device.Ws28xx.Esp32;
45
using nanoFramework.AtomMatrix;
56
using System;
67
using System.Diagnostics;
@@ -11,7 +12,7 @@ namespace AtomMatrixTestApp
1112
{
1213
public class Program
1314
{
14-
private static PixelController _ledMatrix;
15+
private static Ws2812c _ledMatrix;
1516

1617
public static void Main()
1718
{
@@ -23,20 +24,23 @@ public static void Main()
2324
DrawDiagonalLine(Color.Green);
2425
Thread.Sleep(1000);
2526

26-
_ledMatrix.TurnOff();
27+
_ledMatrix.Image.Clear();
28+
_ledMatrix.Update();
2729

2830
// diagonal blue line
2931
DrawDiagonalLine(Color.Blue);
3032
Thread.Sleep(1000);
3133

32-
_ledMatrix.TurnOff();
34+
_ledMatrix.Image.Clear();
35+
_ledMatrix.Update();
3336

3437
// diagonal red line
3538
DrawDiagonalLine(Color.Red);
3639
Thread.Sleep(1000);
3740

3841
// clear LEDs
39-
_ledMatrix.TurnOff();
42+
_ledMatrix.Image.Clear();
43+
_ledMatrix.Update();
4044

4145
button.ButtonDown += Button_ButtonDown;
4246
button.ButtonUp += Button_ButtonUp;
@@ -48,22 +52,24 @@ public static void Main()
4852

4953
private static void DrawDiagonalLine(Color color)
5054
{
51-
_ledMatrix.SetColor(0, color);
52-
_ledMatrix.SetColor(5 + 1, color);
53-
_ledMatrix.SetColor(10 + 2, color);
54-
_ledMatrix.SetColor(15 + 3, color);
55-
_ledMatrix.SetColor(20 + 4, color);
55+
_ledMatrix.Image.SetPixel(0, 0, color);
56+
_ledMatrix.Image.SetPixel(1, 1, color);
57+
_ledMatrix.Image.SetPixel(2, 2, color);
58+
_ledMatrix.Image.SetPixel(3, 3, color);
59+
_ledMatrix.Image.SetPixel(4, 4, color);
5660
_ledMatrix.Update();
5761
}
5862

5963
private static void Button_ButtonUp(object sender, EventArgs e)
6064
{
61-
_ledMatrix.TurnOff();
65+
_ledMatrix.Image.Clear();
66+
_ledMatrix.Update();
6267
}
6368

6469
private static void Button_ButtonDown(object sender, EventArgs e)
6570
{
66-
_ledMatrix.FillColor(Color.Green);
71+
_ledMatrix.Image.Clear(Color.Green);
72+
_ledMatrix.Update();
6773
}
6874
}
6975
}

Tests/AtomMatrixTestApp/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" />
4+
<package id="nanoFramework.Hardware.Esp32.Rmt" version="1.2.2" targetFramework="netnanoframework10" />
45
<package id="nanoFramework.Iot.Device.Button" version="1.0.300" targetFramework="netnanoframework10" />
6+
<package id="nanoFramework.Iot.Device.Ws28xx.Esp32" version="1.0.300" targetFramework="netnanoframework10" />
57
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
68
<package id="nanoFramework.System.Device.Gpio" version="1.0.4" targetFramework="netnanoframework10" />
79
<package id="nanoFramework.System.Drawing" version="1.0.289" targetFramework="netnanoframework10" />

Tests/FireTestApp/FireTestApp.nfproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<HintPath>..\..\packages\nanoFramework.Iot.Device.Mpu6886.1.0.302\lib\Iot.Device.Mpu6886.dll</HintPath>
4646
<Private>True</Private>
4747
</Reference>
48+
<Reference Include="Iot.Device.Ws28xx.Esp32">
49+
<HintPath>..\..\packages\nanoFramework.Iot.Device.Ws28xx.Esp32.1.0.300\lib\Iot.Device.Ws28xx.Esp32.dll</HintPath>
50+
</Reference>
4851
<Reference Include="mscorlib, Version=1.12.0.4, Culture=neutral, PublicKeyToken=c07d481e9758c731">
4952
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.12.0\lib\mscorlib.dll</HintPath>
5053
<Private>True</Private>
@@ -53,6 +56,9 @@
5356
<HintPath>..\..\packages\nanoFramework.Graphics.1.0.2\lib\nanoFramework.Graphics.dll</HintPath>
5457
<Private>True</Private>
5558
</Reference>
59+
<Reference Include="nanoFramework.Hardware.Esp32.Rmt">
60+
<HintPath>..\..\packages\nanoFramework.Hardware.Esp32.Rmt.1.2.2\lib\nanoFramework.Hardware.Esp32.Rmt.dll</HintPath>
61+
</Reference>
5662
<Reference Include="nanoFramework.ResourceManager, Version=1.1.4.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
5763
<HintPath>..\..\packages\nanoFramework.ResourceManager.1.1.4\lib\nanoFramework.ResourceManager.dll</HintPath>
5864
<Private>True</Private>
@@ -101,6 +107,9 @@
101107
<HintPath>..\..\packages\nanoFramework.System.Device.Spi.1.0.5\lib\System.Device.Spi.dll</HintPath>
102108
<Private>True</Private>
103109
</Reference>
110+
<Reference Include="System.Drawing">
111+
<HintPath>..\..\packages\nanoFramework.System.Drawing.1.0.289\lib\System.Drawing.dll</HintPath>
112+
</Reference>
104113
<Reference Include="System.Math, Version=1.4.4.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
105114
<HintPath>..\..\packages\nanoFramework.System.Math.1.4.4\lib\System.Math.dll</HintPath>
106115
<Private>True</Private>

Tests/FireTestApp/Program.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Iot.Device.Ws28xx.Esp32;
45
using nanoFramework.M5Stack;
56
using nanoFramework.Presentation.Media;
67
using System;
@@ -14,6 +15,27 @@
1415
Fire.InitializeScreen();
1516
Console.Clear();
1617

18+
// Testing colors
19+
const int Count = 10;
20+
var neo = Fire.LedBar;
21+
Console.ForegroundColor = Color.White;
22+
Console.WriteLine("All led bar White");
23+
ColorWipe(neo, System.Drawing.Color.White, Count);
24+
Console.ForegroundColor = Color.Red;
25+
Console.WriteLine("All led bar Red");
26+
ColorWipe(neo, System.Drawing.Color.Red, Count);
27+
Console.ForegroundColor = Color.Green;
28+
Console.WriteLine("All led bar Green");
29+
ColorWipe(neo, System.Drawing.Color.Green, Count);
30+
Console.ForegroundColor = Color.Blue;
31+
Console.WriteLine("All led bar blue");
32+
ColorWipe(neo, System.Drawing.Color.Blue, Count);
33+
Console.ForegroundColor = Color.White;
34+
Console.WriteLine("All led rainbow");
35+
Rainbow(neo, Count);
36+
neo.Image.Clear();
37+
neo.Update();
38+
1739
// Test the console display
1840
Console.Write("This is a short text. ");
1941
Console.ForegroundColor = Color.Red;
@@ -123,3 +145,45 @@
123145
Console.Write($" Full {power.IsBatteryFull} ");
124146
Thread.Sleep(20);
125147
}
148+
149+
void ColorWipe(Ws28xx neo, System.Drawing.Color color, int count)
150+
{
151+
BitmapImage img = neo.Image;
152+
for (var i = 0; i < count; i++)
153+
{
154+
img.SetPixel(i, 0, color);
155+
neo.Update();
156+
}
157+
}
158+
159+
void Rainbow(Ws28xx neo, int count, int iterations = 1)
160+
{
161+
BitmapImage img = neo.Image;
162+
for (var i = 0; i < 255 * iterations; i++)
163+
{
164+
for (var j = 0; j < count; j++)
165+
{
166+
img.SetPixel(j, 0, Wheel((i + j) & 255));
167+
}
168+
169+
neo.Update();
170+
}
171+
}
172+
173+
System.Drawing.Color Wheel(int position)
174+
{
175+
if (position < 85)
176+
{
177+
return System.Drawing.Color.FromArgb(position * 3, 255 - position * 3, 0);
178+
}
179+
else if (position < 170)
180+
{
181+
position -= 85;
182+
return System.Drawing.Color.FromArgb(255 - position * 3, 0, position * 3);
183+
}
184+
else
185+
{
186+
position -= 170;
187+
return System.Drawing.Color.FromArgb(0, position * 3, 255 - position * 3);
188+
}
189+
}

Tests/FireTestApp/packages.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" />
44
<package id="nanoFramework.Graphics" version="1.0.2" targetFramework="netnanoframework10" />
5+
<package id="nanoFramework.Hardware.Esp32.Rmt" version="1.2.2" targetFramework="netnanoframework10" />
56
<package id="nanoFramework.Iot.Device.Bmm150" version="1.0.300" targetFramework="netnanoframework10" />
67
<package id="nanoFramework.Iot.Device.Button" version="1.0.300" targetFramework="netnanoframework10" />
78
<package id="nanoFramework.Iot.Device.Buzzer" version="1.0.302" targetFramework="netnanoframework10" />
89
<package id="nanoFramework.Iot.Device.Ip5306" version="1.0.302" targetFramework="netnanoframework10" />
910
<package id="nanoFramework.Iot.Device.Mpu6886" version="1.0.302" targetFramework="netnanoframework10" />
11+
<package id="nanoFramework.Iot.Device.Ws28xx.Esp32" version="1.0.300" targetFramework="netnanoframework10" />
1012
<package id="nanoFramework.ResourceManager" version="1.1.4" targetFramework="netnanoframework10" />
1113
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
1214
<package id="nanoFramework.Runtime.Native" version="1.5.4" targetFramework="netnanoframework10" />
@@ -19,6 +21,7 @@
1921
<package id="nanoFramework.System.Device.Model" version="1.0.300" targetFramework="netnanoframework10" />
2022
<package id="nanoFramework.System.Device.Pwm" version="1.0.1" targetFramework="netnanoframework10" />
2123
<package id="nanoFramework.System.Device.Spi" version="1.0.5" targetFramework="netnanoframework10" />
24+
<package id="nanoFramework.System.Drawing" version="1.0.289" targetFramework="netnanoframework10" />
2225
<package id="nanoFramework.System.Math" version="1.4.4" targetFramework="netnanoframework10" />
2326
<package id="nanoFramework.System.Numerics" version="1.0.289" targetFramework="netnanoframework10" />
2427
<package id="UnitsNet.nanoFramework.ElectricCurrent" version="4.127.0" targetFramework="netnanoframework10" />

0 commit comments

Comments
 (0)