Hello, the code triggers all ports on and off. However, I need to address a specific pin (e.g. A0) and don't know how to implent it.
Appreciate any help as Adafruit library didn't work for me with the 2560.
#include <Wire.h>
const byte mcp_address=0x20; // I2C Address of MCP23017 Chip
const byte GPIOA=0x12; // Register Address of Port A
const byte GPIOB=0x13; // Register Address of Port B
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Wire.beginTransmission(mcp_address);
Wire.write((byte)0x00); // IODIRA register
Wire.write((byte)0x00); // set all of bank A to outputs
Wire.write((byte)0x00); // set all of bank B to outputs
Wire.endTransmission();
}
void loop()
{
Wire.beginTransmission(mcp_address);
Wire.write(GPIOA); // address bank B
Wire.write((byte)0xFF); // value to send - all HIGH ([u]I need only one pin and not all[/u])
Wire.endTransmission();
delay(500);
Wire.beginTransmission(mcp_address);
Wire.write(GPIOA); // address bank B
Wire.write((byte)0x00); // value to send - all LOW
Wire.endTransmission();
delay(500);
Wire.beginTransmission(mcp_address);
Wire.write(GPIOB); // address bank B
Wire.write((byte)0xFF); // value to send - all HIGH
Wire.endTransmission();
delay(500);
Wire.beginTransmission(mcp_address);
Wire.write(GPIOB); // address bank B
Wire.write((byte)0x00); // value to send - all LOW
Wire.endTransmission();
delay(500);
}