I am building my own 4 wheeled dc motor car that I want to move in random patterns (direction and distance). In order to clean up my code and to practice with arduino I am attempting to create my own library.
the end goal would be to call library functions from the library I am creating along with a random number generator
something to the effect of :
#include "customlibrary.h"
void setup()
{
//standard serial setup stuff
}
void loop()
{
int distance = random(0,5); // generate a random distance from 0 - 5
int speed = random(0,3); // generate a random speed 0 -3,
int direction = random(1,4); //generate a random integer to correspond to direction
int time = random(500,3000); //generate a random time between 500 and 3000
switch(direction):
case 1: // direction 1 is forward
customlibrary.fuction1(speed); //set all wheels to the randomyl generated speed
while(int i=distance;i>=0;i--)
{
customlibrary.function2(distance); //make the car go forward for random distance
}
customlibrary.fuction3(); //stop the car
delay(time);
break;
case 2: //direction 2 is reverse
//similar stuff as case 1
break;
case 3: //etc. etc.
deafult:
customlibrary.function3(); function to stop the car
}
ok so now that you can see the idea I am going for, I am using an official arduino Mega2560 and the adafruit motorshield v2.3.
when creating my custom library wont compile. it gives me an error in the custom library when invoking the adafruit motorshield library commands. Specifically the :
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *FR = AFMS.getMotor(1);
Adafruit_DCMotor *FL = AFMS.getMotor(2);
Adafruit_DCMotor *RR = AFMS.getMotor(3);
Adafruit_DCMotor *RL = AFMS.getMotor(4);
FR,FL,RR,RL are the front left, front right.... wheels. If I dont use this code when I attempt to create the custom library
void forward(int _distance)
{
FR->FORWARD;
FL->FORWARD;
etc.....
}
returns that FR, FL are not defined......
This is the error returned....
Using library adafruit_motor_shield_v2_library_1_0_5 at version 1.0.5 in folder: /home/ubuntu/opt/libraries/latest/adafruit_motor_shield_v2_library_1_0_5
/tmp/ccmbXdx5.ltrans0.ltrans.o: In function `main':
ccmbXdx5.ltrans0.o:(.text.startup+0xe0): undefined reference to `setup'
ccmbXdx5.ltrans0.o:(.text.startup+0xe8): undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
In my custom library I am including the correct adafruit library, which works on my test programs but for some reason wont compile when I try to use it inside of my library.....
Is this some sort of circular error message? can I not set variables using another library function inside of my library?
any help will be greatly appreciated.