[SOLVED] include .h and .cpp in arduino
Hello,
I'd like to clarify something with C/C++/arduino because I don't really understand how it operate. With Arduino, many files (if not all) will have a .ino extension. It seem that arduino ide take care of many things in background.
I explain my tests and problems :
I have an arduino sketch like this :
For clarity of code, I want to write "my_function" in another file, not the main .ino. my_function will use 'lcd'.
If I place the code in my_funtion.ino, all is fine :
But if I use my_function.h :
and my_function.cpp :
I add in main.ino
When I compile the sketch I have an error that state :
How can I make others files (.h and .cpp) to know declarations from others files (like main.ino in this case).
thanks,
Manu
Hello,
I'd like to clarify something with C/C++/arduino because I don't really understand how it operate. With Arduino, many files (if not all) will have a .ino extension. It seem that arduino ide take care of many things in background.
I explain my tests and problems :
I have an arduino sketch like this :
Code:
#include <RA8875.h>
#define RA8875_CS 15
#define RA8875_RESET 16
RA8875 lcd = RA8875(RA8875_CS, RA8875_RESET);
void setup() {
Serial.begin(115200);
delay(100);
my_function();
}
For clarity of code, I want to write "my_function" in another file, not the main .ino. my_function will use 'lcd'.
If I place the code in my_funtion.ino, all is fine :
Code:
int my_function() {
lcd.fillQuad(89, 165, 123, 165, 94, 274, 60, 274, RA8875_BLUE);
return 1;
}
But if I use my_function.h :
Code:
#ifndef my_function_h
#define my_function_h
int my_function();
#endif
and my_function.cpp :
Code:
#include "my_function.h"
int my_function() {
lcd.fillQuad(89, 165, 123, 165, 94, 274, 60, 274, RA8875_BLUE);
return 1;
}
I add in main.ino
Code:
#include "my_function.h"
When I compile the sketch I have an error that state :
Code:
my_function.cpp:2: error: 'lcd' was not declared in this scope
my_function.cpp:2: error: 'RA8875_BLUE' was not declared in this scope
How can I make others files (.h and .cpp) to know declarations from others files (like main.ino in this case).
thanks,
Manu
Last edited: