How to program for two Arduinos with different code but share one same .h?

I am now programming for two Arduinos. One is used as Tx and the other is Rx. Of course they are programmed by different codes, but they share some same .h files I programmed(let's say 'share.h'), which are not libraries and shouldn't be put in Arduino's 'library' folder.

So I put 'share.h' and main.ino in one folder, and the ino is like:

#include "share.h"
#define TX
#ifdef TX
void setup(){...something for Tx...}
void loop(){...}
void setup(){...something for Rx...}
void loop(){...}

The shortage is that every time I want to update my code to the two unos, I have to: first change the board port to 40(the Tx uno) in ide, add the #define line, and upload. Then I have to change port to 42(the Rx one), comment the #define line and upload. So inconvenient!

So do you have any good ideas? Much appreciation!

Where do you define the rx and rx pins? In the library or in the sketch?

Where do you define the rx and rx pins? In the library or in the sketch?

In my .ino code.

Just treat the .h as a lib!


Just treat the .h as a lib!


No I don want to do that. If put it in ide's lib folder, it is hard to use git...

Just save one sketch as the rx and another as the rx, put the .h in both folders???

You should put the .h file into your own sketch library folder. Wherever you have put your Arduino Sketches, something like My Documents\Arduino, there should be a libraries folder and there should be a folder in that with the exact same name as your .h file, without the ".h" For example:

My Documents\Arduino\libraries\share\share.h

Then you can #include "share.h" in both sketches and there's only one copy of the file.