/// <summary> /// Initializes a new instance of the <see cref="Mcp23017InputBinaryPin"/> 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 Mcp23017InputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin, Mcp23017PinResistor resistor = Mcp23017PinResistor.None, Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal) { this.connection = connection; this.pin = pin; connection.SetDirection(pin, Mcp23017PinDirection.Input); connection.SetResistor(pin, resistor); connection.SetPolarity(pin, polarity); }
/// <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); }
static void Main(string[] args) { var sdaPin = ConnectorPin.P1Pin03.ToProcessor(); var sclPin = ConnectorPin.P1Pin05.ToProcessor(); using (var driver = new I2cDriver(sdaPin, sclPin)) { var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20)); deviceConnection.SetDirection(Mcp23017Pin.B0, Mcp23017PinDirection.Output); while (!Console.KeyAvailable) { deviceConnection.Toogle(Mcp23017Pin.B0); Thread.Sleep(1000); } } }
private static Hd44780Configuration LoadMcp23017Configuration(IEnumerable<string> args) { var addressText = args.SkipWhile(s => !String.Equals(s, "mcp23017", StringComparison.InvariantCultureIgnoreCase)).Skip(1).DefaultIfEmpty("0x20").First(); var address = addressText.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase) ? Int32.Parse(addressText.Substring(2), NumberStyles.HexNumber) : Int32.Parse(addressText); const Mcp23017Pin registerSelectPin = Mcp23017Pin.B7; const Mcp23017Pin clockPin = Mcp23017Pin.B5; var dataPins = new[] { Mcp23017Pin.B1, Mcp23017Pin.B2, Mcp23017Pin.B3, Mcp23017Pin.B4 }; Console.WriteLine(); Console.WriteLine("Using I2C connection over MCP23017 Expander"); Console.WriteLine("\tRegister Select: {0}", registerSelectPin); Console.WriteLine("\tClock: {0}", clockPin); Console.WriteLine("\tData 1: {0}", dataPins[0]); Console.WriteLine("\tData 2: {0}", dataPins[1]); Console.WriteLine("\tData 3: {0}", dataPins[2]); Console.WriteLine("\tData 4: {0}", dataPins[3]); Console.WriteLine("\tBacklight: VCC"); Console.WriteLine("\tRead/write: GND"); Console.WriteLine(); const ConnectorPin sdaPin = ConnectorPin.P1Pin03; const ConnectorPin sclPin = ConnectorPin.P1Pin05; var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()) { ClockDivider = 512 }; var connection = new Mcp23017I2cConnection(driver.Connect(address)); return new Hd44780Configuration(driver) { Pins = new Hd44780Pins( connection.Out(registerSelectPin), connection.Out(clockPin), dataPins.Select(pin => (IOutputBinaryPin)connection.Out(pin))) }; }
static void Main() { const ConnectorPin sdaPin = ConnectorPin.P1Pin03; const ConnectorPin sclPin = ConnectorPin.P1Pin05; Console.WriteLine("MCP-23017 Sample: Switch LED on B0 pin"); Console.WriteLine(); Console.WriteLine("\tSDA: {0}", sdaPin); Console.WriteLine("\tSCL: {0}", sclPin); Console.WriteLine(); using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor())) { var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20)); deviceConnection.SetDirection(Mcp23017Pin.B0, Mcp23017PinDirection.Output); while (!Console.KeyAvailable) { deviceConnection.Toogle(Mcp23017Pin.B0); Thread.Sleep(1000); } } }
private static Hd44780Configuration LoadI2cConfiguration() { const Mcp23017Pin registerSelectPin = Mcp23017Pin.B0; const Mcp23017Pin clockPin = Mcp23017Pin.B1; var dataPins = new[] { Mcp23017Pin.B2, Mcp23017Pin.B3, Mcp23017Pin.B4, Mcp23017Pin.B5 }; Console.WriteLine(); Console.WriteLine("Using I2C connection"); Console.WriteLine("\tRegister Select: {0}", registerSelectPin); Console.WriteLine("\tClock: {0}", clockPin); Console.WriteLine("\tData 1: {0}", dataPins[0]); Console.WriteLine("\tData 2: {0}", dataPins[1]); Console.WriteLine("\tData 3: {0}", dataPins[2]); Console.WriteLine("\tData 4: {0}", dataPins[3]); Console.WriteLine(); const ConnectorPin sdaPin = ConnectorPin.P1Pin03; const ConnectorPin sclPin = ConnectorPin.P1Pin05; var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()); driver.ClockDivider = 2048; var connection = new Mcp23017I2cConnection(driver.Connect(0x20)); return new Hd44780Configuration(driver) { RegisterSelect = connection.Out(registerSelectPin), Clock = connection.Out(clockPin), Data = dataPins.Select(pin=>connection.Out(pin)) }; }