我目前正在上课以控制 3 个直流电机
在 Arduino 中
我在 Arduino(主要)中创建了 4 个对象
这是代码:
但是当我运行这段代码时,会发生很多这样的错误
'elevator' does not name a type
'elv1' was not declared in this scope
'elv2' was not declared in this scope
'elv3' was not declared in this scope
'elv4' was not declared in this scope
所以,我希望这里的人能提供一些帮助,关于我如何让我的类(class)工作。
先感谢您
这是我的代码
elevator.h
:#ifndef elevator_H
#define elevator_H
class elevator {
public:
int pos(int swa, int swb,int swc ,int swd);
void forwardDC(int A11,int A22);
void reverseDC(int A11,int A22);
void Breaking(int A11,int A22);
void stopDC(int A11,int A22);
char dir;
};
#endif
这是
elevator.cpp
:#include "Arduino.h"
#include "elevator.h"
int elevator::pos(int swa ,int swb ,int swc ,int swd) {
int flag =0;
if (flag >= 4)
flag = 0;
if (digitalRead(swa) == HIGH)
flag = 1;
if (digitalRead(swb) == HIGH)
flag = 2;
if (digitalRead(swc) == HIGH)
flag = 3;
if (digitalRead(swd) == HIGH)
flag = 4;
return flag;
}
void elevator::forwardDC(int A11,int A22) {
digitalWrite(A1, LOW);
digitalWrite(A2, HIGH);
elevator::dir = 'F';
delay(1000);
}
Arduino (.ino) 中的这个声明:
#include <elevator.h>
elevator elv1;
elevator elv2;
elevator elv3;
elevator elv;
最佳答案
当你使用
#include <elevator.h>
它意味着来自库文件夹的库。相反,尝试
#include "elevator.h"
关于class - Arduino 类 "does not name a type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17495364/