Hello I am new to coding I don't know how to code anyways, I found this code online I am trying to build and RC robot that avoid obstacles and can be controlled by bluetooth anyways this is the code to program the DC motors but I am using arduino motor shield R3 and this guys is using AdFruitmotor shield so I tried to add my motor library and arduino.h and verify the code but I get Error compiling.
This is the code:
// Michelino
// Robot Vehicle firmware for the Arduino platform
//
// Copyright (c) 2013 by Miguel Grinberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
- @file michelino.ino
- @brief Arduino robot vehicle firmware.
-
@author Miguel Grinberg
*/
#define ENABLE_ADAFRUIT_MOTOR_DRIVER
#ifdef ENABLE_ADAFRUIT_MOTOR_DRIVER
#include <AFMotor.h>
#include <ArduMotorShield.h>
#include <Arduino.h>
#include "adafruit_motor_driver.h"
#define LEFT_MOTOR_INIT 1
#define RIGHT_MOTOR_INIT 3
#endif
namespace Michelino
{
class Robot
{
public:
/*
-
@brief Class constructor.
*/
Robot()
: leftMotor(LEFT_MOTOR_INIT), rightMotor(RIGHT_MOTOR_INIT)
{
initialize();
}
/*
-
@brief Initialize the robot state.
*/
void initialize()
{
state = stateStopped;
startTime = millis();
}
/*
- @brief Update the state of the robot based on input from sensor and remote control.
- Must be called repeatedly while the robot is in operation.
*/
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;
};
};
Michelino::Robot robot;
void setup()
{
robot.initialize();
}
void loop()
{
robot.run();
}
These are the Error codes:
In file included from michelino.ino:36:
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h:42: error: 'AF_DCMotor' does not name a type
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h: In constructor 'Michelino::Motor::Motor(int)':
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h:19: error: class 'Michelino::Motor' does not have any field named 'motor'
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h: In member function 'virtual void Michelino::Motor::setSpeed(int)':
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h:27: error: 'motor' was not declared in this scope
C:\Users\Shiro\Documents\Arduino\libraries\michelino-0.1/adafruit_motor_driver.h:31: error: 'motor' was not declared in this scope
Please help me I want to fix this code its been a week and am searching for a useful working code with no luck but this code is from the tut "that am following" creator