Whats Wrong in this code?

Whats wrong in this code I keep on getting these error I copied on online am still a newbie to write one

This is the website: Building an Arduino Robot, Part IV: A (Not So) Basic Robot Firmware - miguelgrinberg.com

This is My Code:

#define ENABLE_ARDUMOTORSHIELD_MOTOR_DRIVER

#ifdef ENABLE_ARDUMOTORSHIELD_MOTOR_DRIVER
#include <ArdumotorShield.h>
#include "ardumotorshield_motor_driver.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();

}

My errors:
Neptune.ino:5:42: error: ardumotorshield_motor_driver.h: No such file or directory
Neptune.ino: In constructor 'Neptune::robot::Robot()':
Neptune:17: error: class 'Neptune::Robot' does not have any field named 'leftMotor'
Neptune:17: error: class 'Neptune::Robot' does not have any field named 'rightMotor'
Neptune.ino: In member function 'void Neptune::robot::initialize()':
Neptune:24: error: 'leftMotor' was not declared in this scope
Neptune:25: error: 'rightMotor' was not declared in this scope
Neptune.ino: In member function 'void Neptune::robot::run()':
Neptune:32: error: 'startTime' was not declared in this scope
Neptune:33: error: 'state' was not declared in this scope
Neptune:34: error: 'stateStopped' was not declared in this scope
Neptune:36: error: 'leftMotor' was not declared in this scope
Neptune:37: error: 'rightMotor' was not declared in this scope
Neptune:38: error: 'stateRunning' was not declared in this scope
Neptune:42: error: 'stateRunning' was not declared in this scope
Neptune:44: error: 'leftMotor' was not declared in this scope
Neptune:45: error: 'rightMotor' was not declared in this scope
Neptune:53: error: expected primary-expression before 'private'
Neptune:53: error: expected ;' before 'private' Neptune:55: error: 'Motor' was not declared in this scope Neptune:55: error: expected ;' before 'rightMotor'
Neptune.ino: At global scope:
Neptune:75: error: expected `}' at end of input

This is a Code to make a 2 DC motors to go forward and backward

ardumotorshield_motor_driver.h: No such file or directory

This is a wild guess so please excuse me if I am wrong, but I think that this error is caused by the fact that the file named ardumotorshield_motor_driver.h does not exist where the compiler expects to find it.

Does it exist on your system and if so exactly where is it located ?

ardumotorshield_motor_driver.h :astonished:

WHO even gives a library file a name like that?

LOL I just followed a tut but I noticed this and changed it but the rest of the errors are still there ::slight_smile:

FatmaBinDuwya_:
LOL I just followed a tut but I noticed this and changed it but the rest of the errors are still there ::slight_smile:

I'm not even saying it was wrong. But some versions of the IDE will even baulk at the underscores in a library name.

I found this code but each motor spin alone the the right first spins backward then the left spin forward each one at a time and I don't know why sometime I put it on the ground and it moves little bit "it turns" then it stops

the code:

void setup() {

//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin

//Setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel A pin
pinMode(8, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

//Motor A forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed

//Motor B backward @ half speed
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
analogWrite(11, 123); //Spins the motor on Channel B at half speed

delay(3000);

digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B

delay(1000);

//Motor A forward @ full speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed

//Motor B forward @ full speed
digitalWrite(13, HIGH); //Establishes forward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
analogWrite(11, 255); //Spins the motor on Channel B at full speed

delay(3000);

digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B

delay(1000);

}

KenF:
I'm not even saying it was wrong. But some versions of the IDE will even baulk at the underscores in a library name.

KenF:
I'm not even saying it was wrong. But some versions of the IDE will even baulk at the underscores in a library name.

True, but that is an artificial/self-created IDE problem with respect to the library directory name.
You can name the individual files within the library directory anything you want, since
other parts of the IDE as well as the actually compilers don't care.

Newer versions of the IDE have removed the silly restriction on library directory names.

--- bill

 digitalWrite(9, HIGH);  //Engage the Brake for Channel A
 digitalWrite(9, HIGH);  //Engage the Brake for Channel B

Channel A's brake is on pin 8.

Neptune.ino:5:42: error: ardumotorshield_motor_driver.h: No such file or directory....
Needs attention.

Doc