Arduino Forum

Using Arduino => Programming Questions => Topic started by: applefan1 on May 30, 2011, 02:06 am

Title: Motor Array
Post by: applefan1 on May 30, 2011, 02:06 am
Hi

I have a relatively simple question about initializing a motor array. What I would like to do is set up an array with my 4 motors, but I get an error "cannot convert 'AF_DCMotor' to 'int' in initialization" Could this have to do with my initialization of the individual motors?

Code: [Select]

#include <AFMotor.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

int allMotors[4] = {motor1, motor2, motor3, motor4};


Thanks!
Title: Re: Motor Array
Post by: PaulS on May 30, 2011, 02:08 am
The type of array that things are stored in needs to match the type of things being stored in the array. If you want to store ints in the array, the array type should be int. If you want to store AF_DCMotor objects in an array, the array type should be AF_DCMotor.
Title: Re: Motor Array
Post by: applefan1 on May 30, 2011, 02:30 am
Thank you SO much. Works perfectly.