I am currently making a class in order to control 3 DC motors and in Arduino
and i create 4 object in Arduino (main) Here is the code:
but when i run this code lot of errors occurs like this
'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
So, I would expect some help from people here, regarding how can I make my class work.
Thank you in advance
this is my code
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
and this is 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);
}
this declaration in Arduino (.ino):
#include <elevator.h>
elevator elv1;
elevator elv2;
elevator elv3;
elevator elv;
#includedirective.elevator.handelevator.cppfiles? If they are in the same directory as the.inoyou shall include the header using#include "elevator.h". Otherwise, you shall put them in a directory in the~/Documents/Arduino/librariesdirectory (or the equivalent one you use). Your problem means that the arduino IDE is not finding the header (or worst, it finds another header..)