我有一个ESP32-S2,只要试着用这个简单的脚本测试电路和董事会。错误代码说。
ziel_19-09-2020:在函数'void ()‘:ziel_19-09-2020:85:18:错误:调用重载的'begin(int)’是不明确的mcp1.begin(addr1);在包含在C:\Users/Arduino\ziel_19-09-2020\ziel_19-09-2020.ino:1: C:\Users\Arduino\libraries\Adafruit_MCP23017_Arduino_Library/Adafruit_MCP23017.h:26:8:中的文件中:候选人:'void Adafruit_MCP23017::begin(uint8_t,TwoWire*)‘void (uint8_t addr,TwoWire theWire = &Wire);^ C:\Users\Arduino\libraries\Adafruit_MCP23017_Arduino_Library/Adafruit_MCP23017.h:27:8:备注:候选人:'void Adafruit_MCP23017::begin(TwoWire)‘void (TwoWire *theWire = &Wire);^ exit status 1对重载的'begin(int)’的调用是不明确的
代码是
    #include <Adafruit_MCP23017.h>
#include <math.h> 
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include "SPI.h" 
#define BUTTON_PIN   2   
#define PIXEL_PIN    6  
#define PIXEL_COUNT 136
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_MCP23017 mcp1;
Adafruit_MCP23017 mcp2;
Adafruit_MCP23017 mcp3;
Adafruit_MCP23017 mcp4;
Adafruit_MCP23017 mcp5;
Adafruit_MCP23017 mcp6;
Adafruit_MCP23017 mcp7;
Adafruit_MCP23017 mcp8;
///////////////////////////////////
/////////////Settings//////////////
///////////////////////////////////
int dotcolor_1=0;   
int dotcolor_2=250;
int dotcolor_3=0;
int circlecolor_1=250;
int circlecolor_2=0;
int circlecolor_3=0;
int time_hold=500;
int dtime=3;
///////////////////////////////////
/////////////Settings end//////////
///////////////////////////////////
#define addr1 0
#define addr2 1
#define addr3 2
#define addr4 3
#define addr5 4
#define addr6 5
#define addr7 6
#define addr8 7
double w=0;
double xd;
double yd;
boolean sensor_1[13];
boolean sensor_2[12];
boolean sensor_3[12];
boolean sensor_4[12];
boolean sensor_5[12];
boolean sensor_6[12];
boolean sensor_7[12];
boolean sensor_8[12];
int sen1[12];
int sen2[12];
int sen3[12];
int sen4[12];
int sen5[12];
int sen6[12];
int sen7[12];
int sen8[12];
uint16_t sensor1;
uint16_t sensor2;
uint16_t sensor3;
uint16_t sensor4;
uint16_t sensor5;
uint16_t sensor6;
uint16_t sensor7;
uint16_t sensor8;
void setup() {  
  strip.begin();
 mcp1.begin(addr1);
 mcp2.begin(addr2);
 mcp3.begin(addr3);
 mcp4.begin(addr4);
 mcp5.begin(addr5);
 mcp6.begin(addr6);
 mcp7.begin(addr7);
 mcp8.begin(addr8);
  for(int i=0;i<=15;i++){
  mcp1.pinMode(i, INPUT);
  mcp2.pinMode(i, INPUT);
  mcp3.pinMode(i, INPUT);
  mcp4.pinMode(i, INPUT);
  mcp5.pinMode(i, INPUT);
  mcp6.pinMode(i, INPUT);
  mcp7.pinMode(i, INPUT);
  mcp8.pinMode(i, INPUT);
}发布于 2021-01-12 17:52:03
如果使用#define addr1 0,编译器无法在begin(pointer)和begin(int)之间进行选择,因为来自#define的值可能是一个指针。
如果将I2C地址设置为uint8_t类型的类型化常量,这是begin函数中带有I2C地址的地址参数的类型,则编译器将使用正确的函数。
因此,以const uin8_t addr1 = 0;的方式设置地址
发布于 2021-01-11 18:23:35
基本上,Adafruit_MCP23017库是不好的。您可能需要编辑库。实际上,您可能正在调用两个begin函数,而Arduino不知道您想要哪个函数。
选项1
您可以在setup()之外添加以下行
#define Wire TinyWireM并将begin函数更改为:
 mcp1.begin(addr1, &Wire);
 mcp2.begin(addr2, &Wire);
 mcp3.begin(addr3, &Wire);
 mcp4.begin(addr4, &Wire);
 mcp5.begin(addr5, &Wire);
 mcp6.begin(addr6, &Wire);
 mcp7.begin(addr7, &Wire);
 mcp8.begin(addr8, &Wire);选项2
目前,库中的两个begin函数如下所示:
  void begin(uint8_t addr, TwoWire *theWire = &Wire);
  void begin(TwoWire *theWire = &Wire);我上面的建议是基于假设您使用的是第一个函数。
第二个选项是删除第二个函数。
从Adafruit_MCP23017.cpp中删除以下内容(从第133行开始):
/**
 * Initializes the default MCP23017, with 000 for the configurable part of the
 * address
 * @param theWire the I2C object to use, defaults to &Wire
 */
void Adafruit_MCP23017::begin(TwoWire *theWire) { begin(0, theWire); }从Adafruit_MCP23017.h中删除以下内容(第27行):
  void begin(TwoWire *theWire = &Wire);如果需要的话,我可以进一步指导你编辑图书馆。
https://stackoverflow.com/questions/65671918
复制相似问题