Arduino类“没有命名类型”

时间:2013-07-05 19:02:28

标签: 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

所以,我希望这里的人能得到一些帮助,关于如何让我的班级工作。

提前谢谢

这是我的代码

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;

2 个答案:

答案 0 :(得分:1)

使用时

#include <elevator.h>

它表示来自libraries文件夹的库。相反,尝试

#include "elevator.h"

答案 1 :(得分:0)

您必须添加功能以创建新的电梯变量。

elevator.h

public:
  elevator();
  ...

elevator.cpp

elevator::elevator() {
}