コード例 #1
0
        public static void WaitForAllButtons()
        {
            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()))
            {
                var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20));
                Console.WriteLine("Connected");
                Console.WriteLine("press all 5 of the buttons");

                deviceConnection.SetDirection(Mcp23017Pin.B1, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B3, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B5, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B6, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B7, Mcp23017PinDirection.Input);

                deviceConnection.SetResistor(Mcp23017Pin.B1, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B3, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B5, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B6, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B7, Mcp23017PinResistor.PullUp);


                bool[] btns = { false, false, false, false, false };

                bool btnsPushed = false;
                while (!btnsPushed && !Console.KeyAvailable)
                {
                    Thread.Sleep(100);
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B1))
                    {
                        btns[0] = true; Console.Write("UP ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B3))
                    {
                        btns[1] = true; Console.Write("ENTER ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B5))
                    {
                        btns[2] = true; Console.Write("DOWN ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B6))
                    {
                        btns[3] = true; Console.Write("TOPSEL ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B7))
                    {
                        btns[4] = true; Console.Write("BOTSEL ");
                    }

                    btnsPushed = btns[0] && btns[1] && btns[2] && btns[3] && btns[4];
                }
            }

            Console.WriteLine();
            Console.WriteLine("All buttons pressed");
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ButtonCatcher(PiAndBash.Driver PiAndBashDriver)
        {
            _states = new List <ButtonState>();
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Up, Pin = Mcp23017Pin.B1
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Down, Pin = Mcp23017Pin.B5
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Enter, Pin = Mcp23017Pin.B3
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.TopSel, Pin = Mcp23017Pin.B6
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.BotSel, Pin = Mcp23017Pin.B7
            });



            deviceConnection = PiAndBashDriver.i2cConnection;

            // Always for PnB
            foreach (ButtonState btn in _states)
            {
                deviceConnection.SetDirection(btn.Pin, Mcp23017PinDirection.Input);
                deviceConnection.SetResistor(btn.Pin, Mcp23017PinResistor.PullUp);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017OutputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017OutputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
                                       Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
                                       Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin        = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017OutputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017OutputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
            Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
            Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }