我想为Arduino编写一个简单的库来解析和解释串行命令。我使用示例库的目标是读取预期的命令并打开一些LED。我已经通过arduino获得了串行通信的工作,并且我希望它可以通过库来处理。比如...我有下面的代码在我的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文件。我不确定该从哪里出发,有什么想法?
更改的,得到了这些错误“testingLibraries:2 :错误:'serialComms'没有命名一个类型' 'testingLibraries.ino:在函数'void serialEvent()':' 'testingLibraries:16:错误:'测试'未在此范围内声明' – Bubo 2013-03-09 01:30:25
添加了代码,并修复了错别字。 – mpflaga 2013-03-09 01:50:40
这工作完美,谢谢,我现在有麻烦试图传递数组,我需要使用指针来做到这一点?我不确定 – Bubo 2013-03-12 03:55:06