Arduino Class "does not name type"

I am currently in the class for controlling 3 DC motors and in Arduino

and I create 4 objects in Arduino (main) Here is the code:

but when I run this code a lot of errors 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 the people here regarding how I can do 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 is an ad in Arduino (.ino):

 #include <elevator.h> elevator elv1; elevator elv2; elevator elv3; elevator elv; 
+4
source share
2 answers

When you use

 #include <elevator.h> 

it means a library from a library folder. Try instead

 #include "elevator.h" 
+1
source

You need to add a function to create a new elevator variable.

In elev.h:

 public: elevator(); ... 

In the Elevator.cpp file:

 elevator::elevator() { } 
0
source

Source: https://habr.com/ru/post/1489957/


All Articles