Ejemplo n.º 1
0
        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);
        }