4

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;
6
  • 1
    TL;DR and format your code too. Commented Jul 5, 2013 at 19:03
  • Maybe you should pass an argument to the #include directive. Commented Jul 5, 2013 at 19:11
  • I'm so sooryI can't understand you . you mean like this #include elv1 ?? Commented Jul 5, 2013 at 19:24
  • #include <elevator.h> Commented Jul 5, 2013 at 20:59
  • 2
    where did you save the elevator.h and elevator.cpp files? If they are in the same directory as the .ino you shall include the header using #include "elevator.h". Otherwise, you shall put them in a directory in the ~/Documents/Arduino/libraries directory (or the equivalent one you use). Your problem means that the arduino IDE is not finding the header (or worst, it finds another header..) Commented Jul 5, 2013 at 22:53

2 Answers 2

1

When you use

#include <elevator.h>

it implies a library from the libraries folder. Instead, try

#include "elevator.h"
Sign up to request clarification or add additional context in comments.

Comments

0

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

In elevator.h:

public:
  elevator();
  ...

In elevator.cpp:

elevator::elevator() {
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.