我正在尝试制作一个微型鼠标迷宫解决机器人,我正在遇到一些名为Mouse的类问题。我收到错误:期待';'在'right_motor'和'left_motor'之前。我不知道代码有什么问题。我也不确定我应该在哪里声明我的物体左右马达。这是我的所有代码,谢谢你的帮助。
Mouse.h:
#ifndef _MOUSE_H_
#define _MOUSE_H_
class Mouse
{
private:
int speed;
int motor_num;
int direction;
public:
Mouse(int motor_number);
~Mouse();
void run(int speed, int direction);
};
#endif
Mouse.cpp:
#include "mouse.h"
Mouse::Mouse(int motor_number)
{
motor_num = motor_number;
speed = 0;
direction = 0;
return;
}
// Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
// Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
// Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
// Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
void Mouse::run(int speed, int direction)
{
int M1 = 11;
int M2 = 3;
int M3 = 5;
int M4 = 6;
if(motor_num == 1)
{
if(direction == 1)
{
analogWrite(M1, speed);
}
if(direction == -1)
{
// FIXME: how do i do backwards?
}
if(direction == 0)
{
digitalWrite(M1, LOW);
}
}
if(motor_num == 2)
{
if(direction == 1)
{
analogWrite(M2, speed);
}
if(direction == -1)
{
// FIXME: how do i do backwards?
}
if(direction == 0)
{
digitalWrite(M2, LOW);
}
}
if(motor_num == 3)
{
if(direction == 1)
{
analogWrite(M3, speed);
}
if(direction == -1)
{
// FIXME: how do i do backwards?
}
if(direction == 0)
{
digitalWrite(M3, LOW);
}
}
if(motor_num == 4)
{
if(direction == 1)
{
analogWrite(M4, speed);
}
if(direction == -1)
{
// FIXME: how do i do backwards?
}
if(direction == 0)
{
digitalWrite(M4, LOW);
}
}
return;
}
Arduino草图中的代码:
#include "mouse.h"
void setup()
{
//begin communication with serial port:
Serial.begin(9600);
//pinmodes setup:
//declare variables:
Mouse right_motor(1);
Mouse left_motor(2);
}
void loop()
{
//assign values to their respective variables:
//BEGIN PROGRAM
}
答案 0 :(得分:0)
在MyMouse中更改您的课程(...并更新它的所有参考资料),我认为Mouse是一个内部Arduino库
然后,注意大写字符有时鼠标是大写的,有时是小写的
修改强> 这是Mouse Arduino库 http://www.arduino.cc/en/Reference/MouseKeyboard