私は現在、3つのDCモーターを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;