在为Arduino编写新库之后,编译器无法识别这个新类并返回错误,
BinaryCounter:15:错误:'二进制'没有命名类型
以下是产生错误的文件。该课程在Binary.h
中定义,在Binary.cpp
中实施,并在BinaryCounter.ino
中使用
Binary.h
#ifndef Binary_h
#define Binary_h
#include "Arduino.h"
class Binary {
public:
Binary (int pins[], int numPins);
void display(int number);
void clear();
private:
boolean *_values;
int *_pins;
int _numPins;
void _update();
void _setValues (int num);
};
#endif
Binary.cpp
#include "Binary.h"
Binary::Binary(int pins[], int numPins) {
_values = new boolean[numPins];
_pins = pins;
_numPins = numPins;
for (int i = 0; i < _numPins; i ++) {
pinMode(_pins[i], OUTPUT);
_values[i] = false;
}
_update();
}
void Binary::_update() {
for (int i = 0; i < _numPins; i ++) {
if (_values[i]) {
digitalWrite(_pins[i], HIGH);
} else {
digitalWrite(_pins[i], LOW);
}
}
}
void Binary::_setValues (int num) {
for (int i = 0; i < _numPins; i ++, num/=2) {
_values[i] = ((num%2)==1);
}
}
void Binary::display (int number) {
_setValues(number);
_update();
}
void Binary::clear() {
display(0);
}
和BinaryCounter.ino
#include <Binary.h>
int pins[] = {2,3,4,5,6};
int numPins = 5;
Binary dis(pins, numPins);
void setup() {
}
void loop() {
int loopEnd = 1<<numPins;
for (int i = 0; i < loopEnd; i ++) {
dis.display(i);
delay(200);
}
}
答案 0 :(得分:5)
在文件BinaryCounter中将<Binary.h>
更改为引号"Binary.h"
。
答案 1 :(得分:0)
库/ BinaryCounter /目录中的.cpp和.h是什么? 你创建了keywords.txt文件吗?