Am trying to code for a motor that go forward and backward, this is my code
#define ENABLE_ARDUINO_MOTOR_DRIVER
#ifdef ENABLE_ARDUINO_MOTOR_DRIVER
#include <Arduino.h>
#define LEFT_MOTOR_INIT 1
#define RIGHT_MOTOR_INIT 3
#endif
namespace Neptune
{
class Robot
{
public:
Robot()
: leftMotor(LEFT_MOTOR_INIT), rightMotor(RIGHT_MOTOR_INIT)
{
initialize();
}
void initialize()
{
leftMotor.setSpeed(255);
rightMotor.setSpeed(255);
}
void run()
{
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
switch (state) {
case stateStopped:
if (elapsedTime >= 5000) {
leftMotor.setSpeed(255);
rightMotor.setSpeed(255);
state = stateRunning;
startTime = currentTime;
}
break;
case stateRunning:
if (elapsedTime >= 8000) {
leftMotor.setSpeed(0);
rightMotor.setSpeed(0);
state = stateStopped;
startTime = currentTime;
}
break;
}
}
private:
Motor leftMotor;
Motor rightMotor;
enum state_t {stateStopped, stateRunning };
state_t state;
unsigned long startTime;
};
};
Neptune::Robot robot;
void setup()
{
robot.initialize();
}
void loop()
{
robot.run();
}
When I try to verify my code I get the following errors
Main_MotorDriver:64: error: 'Motor' does not name a type
Main_MotorDriver:65: error: 'Motor' does not name a type
Main_MotorDriver.ino: In constructor 'Neptune:
:Robot()':
Main_MotorDriver:18: error: class 'Neptune::Robot' does not have any field named 'leftMotor'
Main_MotorDriver:18: error: class 'Neptune::Robot' does not have any field named 'rightMotor'
Main_MotorDriver.ino: In member function 'void Neptune:
:initialize()':
Main_MotorDriver:27: error: 'leftMotor' was not declared in this scope
Main_MotorDriver:28: error: 'rightMotor' was not declared in this scope
Main_MotorDriver.ino: In member function 'void Neptune:
:run()':
Main_MotorDriver:40: error: 'leftMotor' was not declared in this scope
Main_MotorDriver:41: error: 'rightMotor' was not declared in this scope
Main_MotorDriver:49: error: 'leftMotor' was not declared in this scope
Main_MotorDriver:50: error: 'rightMotor' was not declared in this scope