我一直在为我的arduino ATMega2560试验I2C和mcp23017 IO扩展器芯片,因为我宁愿在arduino上使用IO自己用于其他事情我只是想弄清楚如何使用adafruit mcp23017.h库并且无法弄清楚如何为了解决多个mcp23017芯片以及如何单独使用这些引脚,这是我编辑的按钮库中的代码.
我希望能够解决各个芯片和引脚我不太确定在设置中,如果多个芯片连接并在代码中寻址,那么IO的引脚模式会从0到15顺序上升.例如,如果第一个芯片被寻址为0x20并且IO数量计数从0到15,如果我添加并寻址另一个芯片为0x21,则该计数将从0到15变为0 - 31.~编辑如果您可以推荐或发送一个更容易或可以帮助的图书馆.
#include <Wire.h>
#include "Adafruit_MCP23017.h"
//pin 1 and 0 are mcp pins not arduino IO pins
Adafruit_MCP23017 mcp;
void setup() {
mcp.begin(); // use default address 0
mcp.pinMode(0, INPUT);
mcp.pinMode(1, OUTPUT);
Serial.begin(9600);
pinMode(13, OUTPUT); // use the p13 LED as debugging
}
void loop() {
// The LED will 'echo' the button
digitalWrite(13, mcp.digitalRead(0)); //Writes pin 13 to the reading of pin 0
mcp.digitalWrite(1, mcp.digitalRead(0)); //Writes pin 1 to the reading of 0
if(mcp.digitalRead(1) …
Run Code Online (Sandbox Code Playgroud)