public static bool InitLEDMatrixes(Nusbio nusbio) { // Use the Nusbio's Adafruit I2C Adapter to plug up to 2 Adafruit LED Matrix // into Nusbio. You can also use a bread board. var clockPin = NusbioGpio.Gpio0; // White var dataOutPin = NusbioGpio.Gpio1; // Green //clockPin = NusbioGpio.Gpio6; //dataOutPin = NusbioGpio.Gpio7; // The first Led matrix must have the default I2C id which is 0x70 // The second one if plugged must have the is 0x71 (A0 Shorted) // Or change the I2C Id // BackPack address A0, A1, A2, (Carefull the label are inversed) // None soldered = 0x70 // A0 Shorted = 0x70 + 1 = 0x71 // A1 Shorted = 0x70 + 2 = 0x72 // A2 Shorted = 0x70 + 4 = 0x74 // A0+A1 Shorted = 0x70 + 2 + 1 = 0x73 // A0+A2 Shorted = 0x70 + 4 + 1 = 0x75 _multiLEDBackpackManager = new MultiLEDBackpackManager(); _multiLEDBackpackManager.Clear(); const byte LED_MATRIX_00_I2C_ADDR = 0x70; _ledMatrix00 = ConsoleEx.WaitOnComponentToBePlugged <LEDBackpack>("LED Matrix", () => { return(_multiLEDBackpackManager.Add(8, 8, nusbio, dataOutPin, clockPin, LED_MATRIX_00_I2C_ADDR)); }); if (_ledMatrix00 == null) { return(false); } // With Nusbio Light because there is no I2C data-in we cannot detect the response // from the connected device. Make sure this first device above is connected. // All other devices below must be connected for the program works correclty. // Or we just do not initialize them if (nusbio.Type == NusbioType.NusbioType1_Light) { return(true); } const byte LED_MATRIX_01_I2C_ADDR = 0x71; _ledMatrix01 = _multiLEDBackpackManager.Add(8, 8, nusbio, dataOutPin, clockPin, LED_MATRIX_01_I2C_ADDR); const byte LED_MATRIX_02_I2C_ADDR = 0x72; _ledMatrix02 = _multiLEDBackpackManager.Add(8, 8, nusbio, dataOutPin, clockPin, LED_MATRIX_02_I2C_ADDR); const byte LED_MATRIX_03_I2C_ADDR = 0x73; _ledMatrix03 = _multiLEDBackpackManager.Add(8, 8, nusbio, dataOutPin, clockPin, LED_MATRIX_03_I2C_ADDR); SetDefaultOrientations(); SetBrightnesses(); return(true); }
static void Main(string[] args) { try { if (MCP2221Device.Detect()) { var d = new MCP2221Device(0); System.Console.WriteLine(d.ToString()); var gpios = d.GetGpioSettings(); d.SetPinDirection(d.GpioIndexes, PinDirection.Output, PinState.Low); //foreach (var index in d.GpioIndexes) //{ // d.DigitalWrite(index, PinState.High); // Thread.Sleep(1 * 100); //} //foreach (var index in d.GpioIndexes) //{ // d.DigitalWrite(index, PinState.Low); // Thread.Sleep(1 * 100); //} var adcs = new List <AnalogDevice>() { d.GetAnalogDevice(1), // Turn the IO into analog d.GetAnalogDevice(2), // Turn the IO into analog d.GetAnalogDevice(3), // Turn the IO into analog }; System.Console.WriteLine($"GetAdcVoltageReference: {adcs[0].GetVoltageReference()}"); while (true) { if (System.Console.KeyAvailable) { var k = System.Console.ReadKey(); if (k.Key == ConsoleKey.Q) { break; } } adcs.ForEach((a) => { System.Console.WriteLine($"AdcVoltageReference: [{a.Index}] {a.GetDigitalValue()} {a.GetVoltage()}"); }); System.Console.WriteLine(""); Thread.Sleep(1000); } //gpios = d.GetGpioSettings(); //d.SetPinDirection(0, PinDirection.Input, PinState.Low); //while (true) //{ // System.Console.WriteLine($"Pin[0] Read:{d.DigitalRead(0)}"); // Thread.Sleep(1 * 1000); //} var ledBackpack = new LEDBackpack(8, 8, d.GetI2CDeviceInstance(0x70)); if (ledBackpack.Detect(0x70)) { ledBackpack.DrawRect(0, 0, 6, 6, true); ledBackpack.WriteDisplay(); } } } catch (Exception ex) { System.Console.WriteLine($"Exception {ex.Message}"); } }