class - Arduino 类 "does not name a type"

标签 class arduino

我目前正在上课以控制 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/

相关文章:

c - 阅读某人的 C 代码,似乎无法破译按位运算

c# - 是否可以在 C# 类库中创建 Windows 窗体?

java - 在替换方法中没有获取值 x 和 y,即(10 和 5)?

c++ - 关于c++中 "this"指针的问题

C++虚拟类基础题

python - 将快速串行数据写入文件(csv 或 txt)

arrays - 如何获取字符串数组的大小

Java 在 JPanel 类之外绘制图像

c++ - Arduino 在另一个类的构造函数中传入一个对象作为参数

c++ - 从 EEPROM 读取并打印到串口