Arduino가 직렬 명령을 구문 분석하고 해석하기위한 간단한 라이브러리를 작성하려고합니다. 예제 라이브러리를 사용하는 나의 목표는 예상되는 명령을 읽고 일부 LED를 켜는 것입니다. 나는 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 : error : 'serialComms'의 이름이 ' '입니다. testingLibraries.ino : 'void serialEvent()': ' 'testingLibraries : 16 : 오류 :이 범위에서'testing '이 (가) 선언되지 않았습니다.' – Bubo
오타가 수정 된 코드가 추가되었습니다. – mpflaga
이것은 완벽하게 작동했습니다. 감사합니다. 지금 배열을 전달하는 데 문제가 있습니다. 포인터를 사용해야합니까? 확실하지 않아요 – Bubo