BMicraft:
So my problem is that if I use "dataPin" as the name for a define I get an error, but if I replace it with another name it works
#define dataPin 4
I've tried to
#undef dataPin
before using that name but it did not work either.
Could this possibly be a bug?
I am using version 1.0.5+dfsg2-2 of the IDE and the Arduino Uno r3
Yes, most likely this is a bug in your code.
If you define "dataPin" which is used in Arduino.h as a parameter in a function declaration, as something else, whithout including Arduino.h first, this is clearly a bug in your code.
You better do either:
#include <Arduino.h>
#define dataPin 4
Or you can define 'dataPin' below some function like:
void somefunction()
{}
#define dataPin 4
The "magic of Arduino" will insert all your missing include files above the first function in your sketch. So if you have some defines above the first function in your sketch, these defines will be active for all the magically included header files, like Arduino.h.
So you can either include all the header files above your define, or you declace a function above your define, so that the header files will be included first before your #define starts unwanted replacing in included header files.
BMicraft:
Thanks, including Arduino.h worked however I would like to know why I get this error when I do not include it.
Doesn't "not including" it basically mean to ignore it? And what about #undef; Shouldn't that have fixed it?
Arduino.h is ALWAYS included in an Arduino program.
Either you include it yourself, or the "magic of Arduino" will include it invisibly for you.
The difference is, WHERE it is included.
If YOU include it that way:
#include <Arduino.h>
#define dataPin 4
Then first 'Arduino.h' is processed and the later #define will not affect any code in Arduino.h.
If the ARDUINO-IDE includes it (invisibly to you), it goes this way:
#define dataPin 4
#include <Arduino.h> // 'invisibly' included by IDE before the first function in your code
In that case every occurance of the identifier 'dataPin' in Arduino.h will be replaced by '4'.
In Arduino the code you write and the code that will be actually compiled is NOT THE SAME. The Arduino-IDE will include several things by itself, like function prototypes and include files - but only if you dont't add them yourself. If you add required function prototypes and include files, Arduino keeps them where you have placed them. If you forget them, Arduino adds them. And that, what is done "magically" by the Arduino-IDE might not always be what you want, such as you do not want to replace the definition of 'dataPin' in the Arduino.h header file.
So be careful with '#define' if this line is placed above the first function in your code!
Such a #define might be in conflict with header files that are included later, even the "magic files" that are included invisibly for you by Arduino.