I can confirm WS2812 Controller still work with RC1 ;-)

Tested:

  • WS2812Controller with a
  • Load Image (8bpp BMP) from 16GB SD Card
  • FEZ Duino
  • WS2812B 32x8 Matrix with 5V 60A Power Supply

Very simple not optimized code:

        private static void RunTextDemo()
    {

        int rows = 8;
        int columns = 32;
        var signalPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA0);
        var sg = new DigitalSignal(signalPin);
        var leds = new WS2812Controller(sg, rows * columns);

        for (int i = 0; i < rows * columns; i++)
        {
            leds.SetColor(i, 0x00, 0x00, 0x00);
        }

        leds.Flush();

        var sd = StorageController.FromName(SC20100.StorageController.SdCard);
        var drive = FileSystem.Mount(sd.Hdc);
        using (System.IO.FileStream fileStream = new FileStream($@"{drive.Name}TinyCLR.bmp", FileMode.Open))
        {
            var image = Image.FromStream(fileStream);

            for (int col = 0; col < image.Width; col++)
            {
                for (int row = 0; row < image.Height; row++)
                {
                    Color c = image.GetPixel(col, row);
                    leds.SetColor(col * rows + (col % 2 != 0 ? rows - row - 1 : row), c.R, c.G, c.B);
                }
            }
        }
        leds.Flush();

    }

What is the better way to update the leds SetBuffer or SetColor ?
And how exactly does SetBuffer work ?

5 Likes

BMP on that simple LED? :slight_smile:

I would use the new BasicGraphics, which already includes simple fonts and shapes for you to easily use. https://docs.ghielectronics.com/software/tinyclr/drivers/software-utility.html

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 https://docs.ghielectronics.com/software/tinyclr/tutorials/encoding-decoding.html#color-space 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? :slight_smile: please!

1 Like

this is not the proper way. you need SC20100.Timer.DigitalSignal.Controller5.PA0

Hi Gus.

Some Background about this “project”.

I teach some kids how a TV is working.

Part 1: 3 LEDs To Demonstrate how Pixel work
Part 2: One RGB Led
Part 3: This LED Matrix.

The Kids can Draw Bitmaps on the PC with a very Simple Application and than they can display it on the LED Matrix. Because it’s cool :slight_smile:

Here is the driver you need

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);

}
1 Like

That is great. Have you signed up for BrainPad insider? The Revolution of Micro-Micro Computing

1 Like