arduino包括自己的图书馆不工作

时间:2014-11-12 23:04:58

标签: c++ c arduino

我试图将我自己的库包含在arduino中。 如果我在同一个文件中包含所有内容,那么当我创建.h.cpp文件时,我会收到错误:

  

TestInclude:6:错误:' JAAMotor'没有命名类型

JAAMotor.h:

#ifndef JAAMOTOR_H
#define JAAMOTOR_H
#include <AFMotor.h>

class JAAMotor {
private:
    boolean lefton;
    AF_DCMotor motor1;
    AF_DCMotor motor2;
    AF_DCMotor motor3;
    AF_DCMotor motor4;
    int mtrspeed;
public:
    JAAMotor();
    void turnleft();
    void turnright();
    boolean getLefton();
    int getspeed();
    void setspeed(int newspeed);
    int stopmotor();
};

#endif

JAAMotor.cpp:

#include <AFMotor.h>
#include <JAAMotor.h>

JAAMotor::JAAMotor() : motor1(1), motor2(2), motor3(3), motor4(4)
{
    motor1.setSpeed(200); //Turn on the Motor
    motor1.run(RELEASE);
    motor2.setSpeed(200); //Turn on the Motor
    motor2.run(RELEASE);
    motor3.setSpeed(200); //Turn on the Motor
    motor3.run(RELEASE);
    motor4.setSpeed(200); //Turn on the Motor
    motor4.run(RELEASE);

}

void JAAMotor::turnleft(){
    if(lefton == false)
    {
        motor1.run(RELEASE);
        motor2.run(RELEASE);
        motor3.run(RELEASE);
        motor4.run(RELEASE);
        delay(500);
        lefton = true;
    }
        motor1.run(BACKWARD);
        motor2.run(BACKWARD);
        motor3.run(FORWARD);
        motor4.run(FORWARD);

}

void JAAMotor::turnright(){
    if(lefton == true)
    {
        motor1.run(RELEASE);
        motor2.run(RELEASE);
        motor3.run(RELEASE);
        motor4.run(RELEASE);
        delay(500);
        lefton = false;
    }
        motor3.run(BACKWARD);
        motor4.run(BACKWARD);
        motor1.run(FORWARD);
        motor2.run(FORWARD);

}

int JAAMotor::getspeed(){
    return mtrspeed;
}

void JAAMotor::setspeed(int newspeed){
    if (newspeed >=0 && newspeed < 256){
        mtrspeed = newspeed;
        motor1.setSpeed(newspeed);
        motor2.setSpeed(newspeed);
        motor3.setSpeed(newspeed);
        motor4.setSpeed(newspeed);
    }
}

int JAAMotor::stopmotor(){
    motor1.run(RELEASE);
    motor2.run(RELEASE);
    motor3.run(RELEASE);
    motor4.run(RELEASE);

}

TestInclude.cpp:

#include <AFMotor.h>
#include <JAAMotor.h>

JAAMotor amotor;

void setup(){

}

//LOOP:
void loop(){
}
//END LOOP
  

TestInclude:6:错误:&#39; JAAMotor&#39;没有命名类型

0 个答案:

没有答案