ERROR Compiling

Hey am trying to program my Robot and am new so I don't know how to code. I found this code online and when I try to compile it I get an error that say Undefined refrence to loop and undefined refrence to function " I searched online and its saying thats because the code didn't have this two main functions", I didn't know where can I add them Can You Please Help me.

/**

  • @file motorshield_motor_driver.h
  • @brief Motor device driver for the Arduino motor shield.
  • @author Nilesh Gulrajani edit by Will Ezell
    */
    #include <Arduino.h>
    #include "motor_driver.h"

namespace Michelino
{
class Motor : public MotorDriver
{
public:
/*

  • @brief Class constructor.
  • @param number the DC motor number to control, from 12 to 13.
    */
    Motor(int number) : MotorDriver(), currentSpeed(0)
    {
    if (number==1){
    MotorSpeedPin = 3;
    MotorDirPin = 12;
    brakePin = 9;
    }
    else if (number==3){
    MotorSpeedPin = 11;
    MotorDirPin = 13;
    brakePin = 8;
    }
    else
    {
    }
    }

void setSpeed(int speed)
{
currentSpeed = speed;
if (speed>0) { //check the direction
digitalWrite(MotorDirPin,HIGH); //set direction pin to forward
digitalWrite(brakePin,LOW); //disengage brake
analogWrite(MotorSpeedPin,currentSpeed); //set speed pin to current speed
}
else if (speed<0){ //check the direction
digitalWrite(MotorDirPin,LOW);// set direction pin to backward
digitalWrite(brakePin,LOW); //disengage brake
analogWrite(MotorSpeedPin,(currentSpeed*(-1))); //set speed pin to current speed
}
else { //check the direction
digitalWrite(brakePin,HIGH); //engage brake
analogWrite(MotorSpeedPin,0); //set speed pin to 0
}
}

int getSpeed() const
{
return currentSpeed;
}

private:
unsigned MotorSpeedPin;
unsigned MotorDirPin;
unsigned brakePin;
int currentSpeed;
};
};

thanks for your time in advance :slight_smile:

It does not compile because it is not a sketch! Read the instructions.

Mark

To make it a sketvh I need to add the loop and setup functions but I don't know were to add them

The code you have listed does not belong in your sketch. it is a library file. It should be stored in the library directory of your sketch folder with a .h extention. There should also be another file with a .cpp extention. Your sketch needs to be created from scratch with just one line to include the library.

I suggest you forget about this library for now and start with some of the simple examples. Maybe just start with This getting started guide. and follow every link until you understand the process.