Pages: [1]   Go Down
Author Topic: Looking for enum and .h guidance  (Read 981 times)
0 Members and 1 Guest are viewing this topic.
Lincoln, NE
Offline Offline
Full Member
***
Karma: 0
Posts: 106
Having lots of fun with Arduino. Thanks everyone!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I got enums to work after reading this:
http://www.arduino.cc/playground/Code/Enum

But, I still have questions  :-?

1. So far, I've been creating new .h elsewhere with NotePad and then adding it to my sketch folder via Sketch > Add File... which would more it to the correct place and make it visible as a tab.  Is this really the best way?!

2. I'd like to share enum between two sketches (one is a transmitter, the other a receiver).  How do I do this without duplicating the .h ?  Creating a library seems overkill for a very specific enum.

3. Would I be better off combining both sketches and set a #define to choose whether to compile the transmitter or receiver?
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would have two .pdes and one .h in my project folder.
/transmitter.pde
/reciever.pde
/shared.h

Then both .pde would: #include "shared.h"
« Last Edit: March 09, 2010, 03:10:42 am by AlphaBeta » Logged

Lincoln, NE
Offline Offline
Full Member
***
Karma: 0
Posts: 106
Having lots of fun with Arduino. Thanks everyone!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I tried putting both transmitter and receiver pde in one folder.
IDE yelled at me for having two setup().  :-(

I think I will stick with const and just maintain them in both pde.  I need to accept that in embedded programming I cannot code defensively.

Thanks for your suggestion.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6654
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. So far, I've been creating new .h elsewhere with NotePad and then adding it to my sketch folder via Sketch > Add File... which would more it to the correct place and make it visible as a tab.  Is this really the best way?!
It looks that way...

Quote
2. I'd like to share enum between two sketches (one is a transmitter, the other a receiver).  How do I do this without duplicating the .h ?  Creating a library seems overkill for a very specific enum.
I think that any code (including .h files) that is shared between multiple sketches *IS* a library.  And probably should be treated as one.  But this doesn't need to be complex.  You can create a directory "harilib" in the appropriate "libraries" directory, and only put shared .h files in it (no .cpp, .pde, or .c required.)  When you "import" the harilib library into your sketch, it will automatically add #includes for all the .h files it finds there, and you can simply delete the ones you don't want...

Quote
3. Would I be better off combining both sketches and set a #define to choose whether to compile the transmitter or receiver?
If you have separate sketches, it might make it easier to make it into a library at a future date...
Logged

Pages: [1]   Go Up
Jump to: