platformio环境下ESP32的Ticker.h库无法编译的解决办法

在PlatformIO环境下遇到Ticker.h导入错误,如nomatchingfunctionforcalltoTicker::Ticker(),通常是由于使用了sstaub/Ticker@4.4.0这个第三方库导致的。解决方法是删除这行引用,改为引用Ticker@2.0.0,后者是ESP32内置的ticker库,可以避免冲突。

如果你在platformio环境下,导了入Ticker.h并且出现例如”no matching function for call to 'Ticker::Ticker()'“之类的报错。那么你大概率是通过下图的方式导入的

解决部分如下:

点开你左侧的资源管理器,找到你的项目后,下滑在test文件夹内找到”platformio.ini“,点击打开,那么你大概率会发现你有一行“sstaub/Ticker @ 4.4.0”语句,

 删除sstaub/Ticker @ 4.4.0,并且输入Ticker @ 2.0.0,问题就可以解决了。

 问题原因:

sstaub/Ticker @ 4.4.0是第三方写的同名库,使用逻辑和网上常见的Ticker库不同。当你修改为Ticker @ 2.0.0时,调用的是esp32内置的ticker库,便不会报错了。

#include<ESP32Servo.h> #include <BLEDevice.h> #include <BLEUtils.h> #include <BLEServer.h> #define BLINKER_BLE //使用蓝牙BLE #include <Blinker.h> //#define BLINKER_BLE //使用蓝牙BLE //定义舵机引脚 #define CTW_PIN 13 Servo CTW;//舵机对象 int CTW_angle = 90;//初始角度 const int ANGLE_STEP=5;//角度变换步长 //blinker组件 BlinkerButton ButtonW("btn_w");//定义键位 //BlinkerButton ButtoNA("btn_a"); //BlinkerButton ButtoNS("btn_s"); //BlinkerButton ButtoND("btn_d"); //舵机保护 void setServoAngle(Servo &CTW,int &angle,int newAngle) { newAngle=constrain(newAngle,0,180);//角度限制 angle=newAngle; CTW.write(angle); char buffer[20]; snprintf(buffer,sizeof(buffer),"Angle:%d",angle); Blinker.print(buffer); } void buttonW_callback(const String&state) { setServoAngle(CTW,CTW_angle,CTW_angle+ANGLE_STEP); //delay(150); } void setup() {// put your setup code here, to run once: Serial.begin(115200);//初始化串口 //初始化舵机 CTW.attach(CTW_PIN); //舵机初始位置 setServoAngle(CTW,CTW_angle,90); Blinker.begin();//初始化Blinker //注册按键回调函数 ButtonW.attach(buttonW_callback); } void loop() { // put your main code here, to run repeatedly: Blinker.run(); } 以上是原代码,接下来是报错:In file included from d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/BlinkerESP32BLE.h:10, from d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Blinker.h:17, from D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\servoa\servoa.ino:6: d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:22:67: error: expected class-name before ',' token 22 | class BlinkerBLE : public BlinkerStream, public BLEServerCallbacks, public BLECharacteristicCallbacks | ^ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:23:1: error: expected class-name before '{' token 23 | { | ^ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:49:9: error: 'BLEServer' does not name a type; did you mean 'Server'? 49 | BLEServer *pServer; | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:50:9: error: 'BLEService' does not name a type 50 | BLEService *pService; | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:51:9: error: 'BLECharacteristic' does not name a type 51 | BLECharacteristic *pCharacteristic; | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:52:9: error: 'BLEAdvertising' does not name a type 52 | BLEAdvertising *pAdvertising; | ^~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:53:9: error: 'BLEAdvertisementData' does not name a type 53 | BLEAdvertisementData pAdvertisementData; | ^~~~~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:64:24: error: 'BLEServer' has not been declared 64 | void onConnect(BLEServer* pServer); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:65:27: error: 'BLEServer' has not been declared 65 | void onDisconnect(BLEServer* pServer); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:66:22: error: 'BLECharacteristic' has not been declared 66 | void onWrite(BLECharacteristic *pCharacteristic); | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: In member function 'void BlinkerBLE::begin()': d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:73:5: error: 'BLEDevice' has not been declared 73 | BLEDevice::init("Blinker"); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:74:5: error: 'pServer' was not declared in this scope; did you mean 'Server'? 74 | pServer = BLEDevice::createServer(); | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:74:15: error: 'BLEDevice' has not been declared 74 | pServer = BLEDevice::createServer(); | ^~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:76:5: error: 'pService' was not declared in this scope 76 | pService = pServer->createService(BLEUUID((uint16_t)0xffe0));//SERVICE_UUID | ^~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:76:39: error: 'BLEUUID' was not declared in this scope 76 | pService = pServer->createService(BLEUUID((uint16_t)0xffe0));//SERVICE_UUID | ^~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:79:5: error: 'pCharacteristic' was not declared in this scope 79 | pCharacteristic = pService->createCharacteristic( | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:81:37: error: 'BLECharacteristic' has not been declared 81 | BLECharacteristic::PROPERTY_READ | | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:82:37: error: 'BLECharacteristic' has not been declared 82 | BLECharacteristic::PROPERTY_NOTIFY | | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:83:37: error: 'BLECharacteristic' has not been declared 83 | BLECharacteristic::PROPERTY_WRITE_NR | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:88:40: error: expected type-specifier before 'BLE2902' 88 | pCharacteristic->addDescriptor(new BLE2902()); | ^~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:93:5: error: 'pAdvertising' was not declared in this scope 93 | pAdvertising = pServer->getAdvertising(); | ^~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:95:5: error: 'BLEAddress' was not declared in this scope; did you mean 'IPAddress'? 95 | BLEAddress otherAddress = BLEDevice::getAddress(); | ^~~~~~~~~~ | IPAddress d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:97:5: error: 'esp_bd_addr_t' was not declared in this scope; did you mean 'esp_ip_addr_t'? 97 | esp_bd_addr_t ble_m_address; | ^~~~~~~~~~~~~ | esp_ip_addr_t d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:12: error: 'ble_m_address' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:27: error: 'otherAddress' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:98:53: error: 'ESP_BD_ADDR_LEN' was not declared in this scope 98 | memcpy(ble_m_address, otherAddress.getNative(), ESP_BD_ADDR_LEN); | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:106:5: error: 'pAdvertisementData' was not declared in this scope 106 | pAdvertisementData.setManufacturerData(macStr); | ^~~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: In member function 'virtual int BlinkerBLE::print(char*, bool)': d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:247:13: error: 'pCharacteristic' was not declared in this scope 247 | pCharacteristic->setValue(s_send.c_str()); | ^~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h: At global scope: d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:6: error: variable or field 'onConnect' declared void 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:28: error: 'BLEServer' was not declared in this scope; did you mean 'Server'? 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:260:39: error: 'pServer' was not declared in this scope; did you mean 'Server'? 260 | void BlinkerBLE::onConnect(BLEServer* pServer) | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:6: error: variable or field 'onDisconnect' declared void 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:31: error: 'BLEServer' was not declared in this scope; did you mean 'Server'? 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:266:42: error: 'pServer' was not declared in this scope; did you mean 'Server'? 266 | void BlinkerBLE::onDisconnect(BLEServer* pServer) | ^~~~~~~ | Server d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:6: error: variable or field 'onWrite' declared void 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:26: error: 'BLECharacteristic' was not declared in this scope 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~~~~~~~~ d:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker\src/Adapters/BlinkerBLE.h:273:45: error: 'pCharacteristic' was not declared in this scope 273 | void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic) | ^~~~~~~~~~~~~~~ Using library ESP32Servo at version 3.0.8 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\ESP32Servo Using library BLE at version 3.2.0 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\BLE Using library Blinker at version 0.3.10230510 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Blinker Using library Ticker at version 4.4.0 in folder: D:\Arduino_IDE\locales\hardware\eap32\arduino-esp32-master\libraries\Ticker Using library EEPROM at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\EEPROM Using library Update at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\Update Using library WiFi at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\WiFi Using library Networking at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\Network Using library NetworkClientSecure at version 3.3.0 in folder: C:\Users\qingc\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.3.0\libraries\NetworkClientSecure exit status 1 Compilation error: exit status 1请问为什么会发生这种报错,哪里需要改正,请给出完整的步骤,如果涉及到代码的更改,请将更改后的完整代码写出
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值