Beispiel #1
0
        public void SetDirection(Port port, Mcp23017PinDirection direction)
        {
            var register = GetRegisterAddress(Register.IODIRA, port);

            var value = (byte)(direction == Mcp23017PinDirection.Input
                ? 0xFF
                : 0x00);

            connection.Write(register, value);
        }
        /// <summary>
        /// Sets the direction.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void SetDirection(Mcp23017Pin pin, Mcp23017PinDirection direction)
        {
            var register = ((int)pin & 0x0100) == 0x0000 ? Register.IODIRA : Register.IODIRB;

            connection.WriteByte((byte)register);
            var directions = connection.ReadByte();

            var bit           = (byte)((int)pin & 0xFF);
            var newDirections = (direction == Mcp23017PinDirection.Input)
                                    ? directions | bit
                                    : directions & ~bit;

            connection.Write(new[] { (byte)register, (byte)newDirections });
        }
        public void SetDirection(Mcp23017Pin pin, Mcp23017PinDirection direction)
        {
            var register = ((int) pin & 0x0100) == 0x0000 ? Register.IODIRA : Register.IODIRB;

            connection.WriteByte((byte)register);
            var directions = connection.ReadByte();

            var bit = (byte)((int)pin & 0xFF);
            var newDirections = (direction == Mcp23017PinDirection.Input)
                                    ? directions | bit
                                    : directions & ~bit;

            connection.Write(new[] { (byte)register, (byte)newDirections });
        }