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 ![]()