I would use the new BasicGraphics, which already includes simple fonts and shapes for you to easily use. Software Utility Drivers
Now your LEDs are inversed every other row (they go zigzag) and you need to invert those, which is 2 lines of code in TinyCLR. Look at swap endianess Encoding & Decoding your group size is 8 since there are 8 led in each line you want to swap!
@Greg_Norris can we actually add this sample to the new drivers section? please!
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Signals;
using GHIElectronics.TinyCLR.Drivers.BasicGraphics;
using GHIElectronics.TinyCLR.Drivers.Worldsemi.WS2812;
namespace GHIElectronics.TinyCLR.Sample.LedMatrix
{
class LedMatrix : BasicGraphics
{
private int row, column;
WS2812Controller leds;
public LedMatrix(GpioPin pin, int row, int column)
{
this.row = row;
this.column = column;
var sg = new SignalGenerator(pin);
this.leds = new WS2812Controller(sg, this.row * this.column);
Clear();
}
public override void Clear()
{
leds.Clear();
}
public override void SetPixel(int x, int y, uint color)
{
if (x < 0 || x >= this.column) return;
if (y < 0 || y >= this.row) return;
// even columns are inverted
if((x & 0x01) !=0)
{
y = this.row -1 - y;
}
var index = x * this.row + y;
leds.SetColor(index, (int) (color >> 16) & 0xff, (int)(color >> 8) & 0xff, (int)(color >> 0) & 0xff);
}
public void Flush()
{
leds.Flush();
}
}
}
And here is how to use
var pin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PC6);
var screen = new LedMatrix(pin, 8, 32);
screen.Clear();
var col = LedMatrix.ColorFromRgb(0, 20, 50);
var c = 0;
while (true)
{
screen.Clear();
screen.DrawString(c++.ToString(), col, 0, 0);
screen.Flush();
Thread.Sleep(10);
}