void Initialize() { var display = new Max7219( device: Device, spiBus: Device.CreateSpiBus(Max7219.DefaultSpiBusSpeed), csPin: Device.Pins.D01, deviceCount: 4, maxMode: Max7219.Max7219Type.Display); graphics = new MicroGraphics(display); graphics.CurrentFont = new Font4x8(); joystick = new AnalogJoystick(Device, Device.Pins.A01, Device.Pins.A02, null, true); joystick.StartUpdating(TimeSpan.FromMilliseconds(20)); }
async Task Initialize() { var onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); var display = new Max7219( device: Device, spiBus: Device.CreateSpiBus(), csPin: Device.Pins.D01, deviceCount: 4, maxMode: Max7219.Max7219Type.Display); graphics = new MicroGraphics(display); graphics.CurrentFont = new Font4x8(); graphics.Rotation = RotationType._180Degrees; graphics.Clear(); graphics.DrawText(0, 1, "WI"); graphics.DrawText(0, 9, "FI"); graphics.DrawText(0, 17, "TI"); graphics.DrawText(0, 25, "ME"); graphics.Show(); pushButton = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp); pushButton.Clicked += PushButtonClicked; analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); var connectionResult = await Device.WiFiAdapter.Connect(Secrets.WIFI_NAME, Secrets.WIFI_PASSWORD); if (connectionResult.ConnectionStatus != ConnectionStatus.Success) { throw new Exception($"Cannot connect to network: {connectionResult.ConnectionStatus}"); } onboardLed.StartPulse(Color.Green); }
static async Task App() { var board = await ConnectionService.Instance.GetFirstDeviceAsync(); await board.ConnectAsync(); var controller = new Max7219(board.Spi, board.Pins[7]); var display = new SevenSegmentDisplay(controller.Leds, true); int i = 0; while (!Console.KeyAvailable) { display.Text = i++; await Task.Delay(10); } board.Disconnect(); }
public void Initialize() { if (initialized) { return; } ledDisplay = new Max7219( MeadowApp.Device, MeadowApp.Device.CreateSpiBus(), MeadowApp.Device.Pins.D00, deviceCount: 4, maxMode: Max7219.Max7219Type.Display); ledDisplay.IgnoreOutOfBoundsPixels = true; canvas = new MicroGraphics(ledDisplay); canvas.Rotation = RotationType._90Degrees; canvas.CurrentFont = new Font4x8(); initialized = true; }
static void Main(string[] args) { Console.WriteLine("Hello Max7219!"); var connectionSettings = new SpiConnectionSettings(0, 0) { ClockFrequency = 10_000_000, Mode = SpiMode.Mode0 }; var spi = new UnixSpiDevice(connectionSettings); using (var devices = new Max7219(spi, cascadedDevices: 4)) { //initialize the devices devices.Init(); // send a display test to the devices: All leds should be lighted Console.WriteLine("Display-Test"); devices.SetRegister(Register.DISPLAYTEST, 1); Thread.Sleep(1000); // 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); } } } }
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(); } } }
static void Main(string[] args) { var message = "Hello World from MAX7219!"; if (args.Length > 0) { message = string.Join(" ", args); } Console.WriteLine(message); var connectionSettings = new SpiConnectionSettings(0, 0) { ClockFrequency = Max7219.SpiClockFrequency, Mode = Max7219.SpiMode }; var spi = SpiDevice.Create(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.Right; 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(message, alwaysScroll: true); } } }
public void Init() { Console.WriteLine("Init..."); display = new Max7219(Device, Device.CreateSpiBus(), Device.Pins.D02, 1, true); }