Hi everyone.
I'm writing a code where I have a struct containing the pinmap of my device on a dedicated file. I then use this struct to initialize the pins and do other stuff. I import the object on another file with extern and try to set pinMode with that pin byte I saved inside this 'p_pinmap' object. This procedure for reasons I cannot understand make the compiler trow "undefined reference to 'p_pinmap' ". If I use digitalWrite or assign the member inside a new variable the complier doesn't complain.
Can somebody explain me what am I doing wrong?
//main.ino
#include "init.h"
#include "parameters.h"
extern const pins p_pinmap;
void setup() {
//initiate the channels
initialize();
}
void loop() {
delay(1000);
}
//init.h
#ifndef _INIT_
#define _INIT_
void initialize();
#endif
//init.cpp
#include "init.h"
#include "parameters.h"
extern const pins p_pinmap;
void initialize(){
pinMode(p_pinmap.LED_Clock,OUTPUT); //undefined reference
pinMode(p_pinmap.Heater[1],OUTPUT); //undefined reference
const byte a=5; //OK
const byte b=p_pinmap.LED_Clock; //OK
pinMode(b,OUTPUT); //undefined reference
pinMode(7,OUTPUT); //OK
pinMode(a,OUTPUT); //OK
}
//parameters.h
#ifndef _PARAMETERS_
#define _PARAMETERS_
#include <Arduino.h>
/*-----PINOUT-----*/
struct pins {
const byte Heater[4];
const byte Temp[4];
const byte AnPot[4];
const byte LED_Clock;
const byte LED_Data;
const byte LED_Latch;
const byte DHTPIN;
pins(): //fill here the pin numbers from 1st channel to the last
Heater({10,11,12,13}),
Temp({2,3,4,5}),
AnPot({A1,A2,A3,A4}),
LED_Clock(6), LED_Data(7), LED_Latch(8), DHTPIN(9) {};
};
#endif
//parameters.cpp
#include "parameters.h"
const pins p_pinmap;