Puzzling Refinitions


hello arduino community,

i planning on building line following robot, in 3 different files, using tinkerkit shield. in first, main, .ino file planning on having main code, i'm not there yet. have file, called globalvar.cpp, have declared variables. then, in third file, have motorfunctions.cpp, planning make functions move servos, far have function set motors.
when tried compile bizarre error message:
code: [select]
arduino: 1.6.3 (mac os x), board: "arduino yún"

in file included car.ino:2:0:
motorfunctions.cpp: in function 'void setupmotors()':
motorfunctions.cpp:10:1: error: 'backrightmotor' not declared in scope
 backrightmotor.attach(backrightmotorpin);
 ^
motorfunctions.cpp:10:23: error: 'backrightmotorpin' not declared in scope
 backrightmotor.attach(backrightmotorpin);
                       ^
motorfunctions.cpp:11:1: error: 'backleftmotor' not declared in scope
 backleftmotor.attach(backleftmotorpin);
 ^
motorfunctions.cpp:11:22: error: 'backleftmotorpin' not declared in scope
 backleftmotor.attach(backleftmotorpin);
                      ^
motorfunctions.cpp:12:1: error: 'frontrightmotor' not declared in scope
 frontrightmotor.attach(frontrightmotorpin);
 ^
motorfunctions.cpp:12:24: error: 'frontrightmotorpin' not declared in scope
 frontrightmotor.attach(frontrightmotorpin);
                        ^
motorfunctions.cpp:13:1: error: 'frontleftmotor' not declared in scope
 frontleftmotor.attach(frontleftmotorpin);
 ^
motorfunctions.cpp:13:23: error: 'frontleftmotorpin' not declared in scope
 frontleftmotor.attach(frontleftmotorpin);
                       ^
car.ino: @ global scope:
car.ino:17:5: error: redefinition of 'int reflectancesensor6'
car.ino:16:5: error: 'int reflectancesensor6' declared here
error compiling.

  report have more information with
  "show verbose output during compilation"
  enabled in file > preferences.


it says have declared variables, declared them in 1 file. here code:
main file:
code: [select]


#include "globalvar.cpp"
#include "motorfunctions.cpp"
#include <servo.h>
#include <tinkerkit.h>




void setup() {


}

void loop() {

}



globalvar.cpp file:

code: [select]

#include <arduino.h>
#include <servo.h>
#include <tinkerkit.h>

//on left side
int reflectancesensor1;
int refectancesenor2;
int reflectancesensor3;


//on right side
int reflectancesensor4;
int reflectancesensor6;
int reflectancesensor6;

int backrightmotorpin = o0;
int backleftmotorpin = o0;
int frontrightmotorpin = o0;
int frontleftmotorpin = o0;

servo backrightmotor;
servo backleftmotor;
servo frontrightmotor;
servo frontleftmotor;

servo mount;


motorfunctions.cpp file:

[code]#include <arduino.h>
#include <servo.h>
#include <tinkerkit.h>

#include "globalvar.cpp"
 

void setupmotors(){
 
backrightmotor.attach(backrightmotorpin);
backleftmotor.attach(backleftmotorpin);
frontrightmotor.attach(frontrightmotorpin);
frontleftmotor.attach(frontleftmotorpin);
}
 




perhaps missing something, have been looking @ quite while, , see no error.

thanks,
         ma7730

whoops, in title meant "redefinitions!"       : ::)


Arduino Forum > Using Arduino > Programming Questions > Puzzling Refinitions


arduino

Comments