1

I am trying to make a micro-mouse maze solving robot, and I'm running into some issues with my class called Mouse. I get the error: expected ';' before 'right_motor' and 'left_motor'. I have no idea what is wrong with the code. I also am not sure exactly where I should declare my objects left and right motors. Here is all my code, thank you for your help.

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;
}

Code in the Arduino sketch:

#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
}

1 Answer 1

0

Change your class in MyMouse (...and update all reference of it), I think Mouse is an internal Arduino library

then, pay attention on Uppercase chars sometimes Mouse is uppercase and sometimes is lowercase

Edit: this is Mouse Arduino library http://www.arduino.cc/en/Reference/MouseKeyboard

Sign up to request clarification or add additional context in comments.

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.