我正在尝试为 Arduino 编写一个简单的库来解析和解释串行命令。我对示例库的目标是读取预期的命令并打开一些 LED。我已经通过 arduino 进行串行通信,我希望它由库处理。例如...我的arduino上有以下代码
Arduino代码:
#include <serialComms.h>
serialComms testing = serialComms();
void setup()
{
Serial.begin(9600);
}
void loop() // not terribly concerned with the main loop, only the serialEvent, which I have tested and works
{
}
void serialEvent()
{
testing.readNewBytes();
testing.assignBytes();
}
serialComms.cpp
#include <Arduino.h>
#include <serialComms.h>
void serialComms::init()
{
// This is where the constructor would be...right now we are too stupid to have one
}
void serialComms::readNewBytes() // Target Pin,Values
{
digitalWrite(11,HIGH);
delay(250);
digitalWrite(11,LOW);
assignBytes();
}
void serialComms::assignBytes()
{
for(int t = 0;t<5;t++)
{
digitalWrite(10,HIGH);
delay(250);
digitalWrite(10,LOW);
}
}
serialComms.h
#ifndef serialComms_h
#define serialComms_h
/* serialComms Class */
class serialComms
{
public:
serialComms() {};
void init();
void readNewBytes(); // Will be used to create the array --> two variables for now...
void assignBytes();
};
#endif
我的问题如下...
1.) 我的库结构是否正确?当我发送消息并触发 serialEvent 时,我只想让 LED 闪烁,当我在 arduino 中运行代码时,会出现以下错误。
testingLibraries:2: error: 'serialComms' does not name a type
testingLibraries.ino: In function 'void serialEvent()':
testingLibraries:16: error: 'testing' was not declared in this scope
我在库文件夹中名为 serialComms 的文件夹中有 .cpp 和 .h 文件。我真的不确定从这里去哪里,有什么想法吗?