Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Max7219!");

            var connectionSettings = new SpiConnectionSettings(0, 0)
            {
                ClockFrequency = Max7219.SpiClockFrequency,
                Mode           = Max7219.SpiMode
            };
            var spi = new UnixSpiDevice(connectionSettings);

            using (var devices = new Max7219(spi, cascadedDevices: 4))
            {
                //initialize the devices
                devices.Init();

                // reinitialize the devices
                Console.WriteLine("Init");
                devices.Init();

                // write a smiley to devices buffer
                var smiley = new byte[] {
                    0b00111100,
                    0b01000010,
                    0b10100101,
                    0b10000001,
                    0b10100101,
                    0b10011001,
                    0b01000010,
                    0b00111100
                };

                for (var i = 0; i < devices.CascadedDevices; i++)
                {
                    for (var digit = 0; digit < 8; digit++)
                    {
                        devices[i, digit] = smiley[digit];
                    }
                }

                // flush the smiley to the devices using a different rotation each iteration.
                foreach (RotationType rotation in Enum.GetValues(typeof(RotationType)))
                {
                    Console.WriteLine($"Send Smiley using rotation {devices.Rotation}.");
                    devices.Rotation = rotation;
                    devices.Flush();
                    Thread.Sleep(1000);
                }

                //reinitialize device and show message using the matrix graphics
                devices.Init();
                devices.Rotation = RotationType.Left;
                var graphics = new MatrixGraphics(devices, Fonts.Default);
                foreach (var font in new[] { Fonts.CP437, Fonts.LCD, Fonts.Sinclair, Fonts.Tiny, Fonts.CyrillicUkrainian })
                {
                    graphics.Font = font;
                    graphics.ShowMessage("Hello World from MAX7219!", alwaysScroll: true);
                }
            }
        }
Beispiel #2
0
        static void Main()
        {
            SpiConnectionSettings connectionSettings = new SpiConnectionSettings(0, 0)
            {
                ClockFrequency = 10000000,
                Mode           = SpiMode.Mode0
            };

            using (SpiDevice spi = SpiDevice.Create(connectionSettings))
            {
                using (Max7219 device = new Max7219(spi))
                {
                    device.Init();

                    // Double init
                    device.Init();

                    device[0] = 0b01010101;
                    device[1] = 0b10101010;
                    device[2] = 0b01010101;
                    device[3] = 0b10111010;
                    device[4] = 0b01011101;
                    device[5] = 0b10111010;
                    device[6] = 0b01011101;
                    device[7] = 0b10111010;

                    device.Flush();

                    Console.WriteLine("Ready for next");
                    Console.ReadLine();



                    // Rotate the image

                    device.Rotation = RotationType.Left;
                    device.Flush();
                    Thread.Sleep(1000);

                    device.Rotation = RotationType.Half;
                    device.Flush();
                    Thread.Sleep(1000);

                    device.Rotation = RotationType.Right;
                    device.Flush();
                    Thread.Sleep(1000);

                    device.Rotation = RotationType.None;
                    device.Flush();

                    Console.WriteLine("Ready for next");
                    Console.ReadLine();



                    // Show some text

                    device.Init();

                    device.Rotation = RotationType.None;

                    MatrixGraphics graphics = new MatrixGraphics(device, Fonts.Default);

                    graphics.ShowMessage("Hello Alt.Net!", alwaysScroll: true);

                    Console.WriteLine("Done!");
                    Console.ReadLine();



                    device.ClearAll();
                }
            }
        }