Class “Arduino级”;不为类型命名";

Class “Arduino级”;不为类型命名";,class,arduino,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 i

我目前正在做一个类,以控制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
所以,我希望这里的人能给我一些帮助,帮助我如何让我的课堂发挥作用

先谢谢你

这是我的密码

电梯.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
这是电梯.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)声明:

#包括
电梯elv1;
电梯elv2;
电梯elv3;
电梯弱电;

必须添加函数才能创建新的电梯变量。

在电梯中。h:

在电梯.cpp中:

当你使用

#include <elevator.h>

TL;DR并格式化您的代码。也许您应该向
#include
指令传递一个参数。很抱歉,我听不懂您的意思。你的意思是这样的#包括elv1???包括你在哪里保存了
lifter.h
lifter.cpp
文件?如果它们与
.ino
位于同一目录中,则应使用
#include“lifter.h”
包含标题。否则,您应将它们放在
~/Documents/Arduino/libraries
目录(或您使用的等效目录)中的目录中。您的问题意味着arduino IDE找不到标头(或者最糟糕的是,它找到了另一个标头..)
public:
  elevator();
  ...
elevator::elevator() {
}
#include <elevator.h>
#include "elevator.h"