我正在尝试使用GPY2Y0A21Y IRsensor,但我无法使代码正常工作。我下载了SharpIR,但在使用其中一个函数时遇到了错误
#include <SharpIR.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SharpIR sharp("A1", 25, 93, 1080);
}
void loop() {
// put your main code here, to run repeatedly:
}
这是错误消息
/var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino: In function 'void setup()':
sketch_jan17a:7: error: no matching function for call to 'SharpIR::SharpIR(const char [3], int, int, int)'
SharpIR sharp("A1", 25, 93, 1080);
^
/var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino:7:33: note: candidates are:
In file included from /var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino:1:0:
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:29:5: note: SharpIR::SharpIR(uint8_t, uint8_t)
SharpIR(uint8_t _sensorType, uint8_t _sensorPin);
^
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:29:5: note: candidate expects 2 arguments, 4 provided
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: constexpr SharpIR::SharpIR(const SharpIR&)
class SharpIR
^
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: candidate expects 1 argument, 4 provided
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: constexpr SharpIR::SharpIR(SharpIR&&)
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: candidate expects 1 argument, 4 provided
exit status 1
no matching function for call to 'SharpIR::SharpIR(const char [3], int, int, int)'
我对图书馆并不是很熟悉,所以我不知道这段代码有什么问题。我得到的只是功能不存在。我确实下载了SharpIR顺便说一句。如果有人可以提供帮助,我们将不胜感激(有这个网站的示例代码https://playground.arduino.cc/Main/SharpIR)
答案 0 :(得分:0)
这个错误似乎是合法的,看着SharpIR declaration。您所关注的指南可能已被弃用且与您安装的库不兼容?
class SharpIR
{
public:
SharpIR (int irPin, long sensorModel);
int distance();
private:
void sort(int a[], int size);
int _irPin;
long _model;
};
对象初始化只需要一个引脚号和一个标识传感器模型的long。 但是在您的问题中查看错误,似乎声明是以传感器标识号作为第一个参数并且引脚号作为第二个来实现的。我认为您应该在本地安装中打开源并检查它。您可以使用以下命令在终端中打印:
cat /Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h
(我现在无法打开Dropbox链接...)