4

我目前正在上课以控制 3 个直流电机和 Arduino

我在 Arduino (main) 中创建了 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;
4

2 回答 2

1

当你使用

#include <elevator.h>

它意味着库文件夹中的库。相反,尝试

#include "elevator.h"
于 2014-03-02T15:08:04.500 回答
0

You have to add the function to create a new elevator variable.

In elevator.h:

public:
  elevator();
  ...

In elevator.cpp:

elevator::elevator() {
}
于 2013-08-06T15:49:31.977 回答