I recently built myself a small 4 wheeled robot chassis powered by an Arduino Uno and an Adafruit MotorShield V2.3. I thought it'd be a good way to practice my programming over the holiday (I'm a CompSci student) and maybe learn a bit of C++ as all my current programming knowledge is in Java. Anyway, I assembled the robot and got it moving, so I'm fairly certain that none of the boards are broken. The next thing I tried to do was to create a wrapper class to contain the setup of the robot and some basic commands (such as forward, reverse and turn). I tried to do this by creating a new library (I followed this tutorial: https://www.arduino.cc/en/Hacking/LibraryTutorial, however this is where I am running into some problems.
First here is the code for my Robot.h file:
Code: Select all
#ifndef Robot_h
#define Robot_h
#include "Arduino.h";
#include <Wire.h>
#include <Adafruit_MotorShield.h>
class Robot
{
public:
Robot();
private:
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
};
#endif
Code: Select all
#include "Arduino.h"
#include "Robot.h"
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Robot::Robot()
{
Serial.begin(9600);
Serial.println("Foo");
AFMS.begin();
Serial.println("Bar");
}
Code: Select all
#include <Robot.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Robot myBot;
void setup()
{
myBot = Robot();
}
void loop()
{
}