Go Down

Topic: declarations in libraries (Read 1 time) previous topic - next topic

Loren

I'm working on a project that I think will be fairly large.  I'm hoping to write some libraries to help maintain the ability to read through it easily.  I did go through the library tutorial but I am confused about where to put a some of the declarations that the library will need to access.

for example I'm working with a ethernet shield and need to declare this all of this:

Code: [Select]
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);


I got an error when I tried to declare it at the top of the header file and when I tried to put it at the top of the source file.  I did try and declare all of it in the main file but that also created problems.  I assume that in this scenario the header and source file don't have access to the variables. 

Any help would be greatly appreciated. 

Thanks,

Loren

PaulS

Quote
I got an error when I tried to declare it at the top of the header file

Those statements declare and initialize the variables. You need to declare them in the header file and initialize them in the source file if you want to share them.

Loren

What is mentioned above makes sense  here is what I attempted:

Code: [Select]
#ifndef Eth_h
#define Eth_h

#include <SPI.h>
#include <Ethernet.h>

byte mac [5];
IPAddress ip;


class Eth{
   
public:
void init();

};
#endif


Which returns the error: 
Code: [Select]
error: 'IPAddress' does not name a type

I thought that IPAddress was a member of the Ethernet source. 

What am I not doing or missing?

michinyon

Ethernet.h    appears to want to include    IPAddress.h ,   so I guess the IPAddress
class is in that .h file.     I can't find it on my computer,  but I never used Ethernet with
arduino,  so I dunno.

Try searching for IPAddress.h  on your computer and see if you have it and it is in the
correct place.

PaulS

Quote
here is what I attempted:

What does your sketch look like? Are you including Ethernet.h in the sketch?

Go Up