I'm trying to figure out how to use .cpp and .h files in the same directory as my sketch, but I'm getting compile errors. I created a simple sketch with 3 files all in the same folder: Include_Lib_Test.ino, MyLib.h & MyLib.cpp. They use a button library, Button.h which is in my libraries folder
Here's the code for the 3 files
// Include_Lib_Test.ino
#include "MyLib.h"
#include <Button.h>
void setup() { }
void loop() {
readbutton();
}
// MyLib.h
#ifndef _MYLIB_H
#define _MYLIB_H
#include <Button.h>
Button helloButton = Button(2, LOW);
void readbutton();
#endif
// MyLib.cpp
#include "MyLib.h"
void readbutton() {
helloButton.listen();
}
I get this compile error:
MyLib.cpp.o: In function `__static_initialization_and_destruction_0':
MyLib.h:5: multiple definition of `helloButton'
Include_Lib_Test.cpp.o:/Applications/Include_Lib_Test.ino:4: first defined here
I attached Button.h and .cpp for reference