#define and const

I was learning some of the syntax of Arduino code using a sketch made by others and came across the #define. I looked it up in the reference where it explained what the command did.

It also said to use "const" instead of "#define" because of potential problems with the latter in code.

So I changed them, compiled and received errors on each one I changed. So I changed them back.

It's not a big deal, but there is some ambiguity with the reference in this regard.

Any comments?

queenidog:
Any comments?

Not without seeing your program.

…R

For pin numbers, change:

#define NamedPin number

to

const byte NamedPin = number;

The errors you got would depend on if you forgot the type ('byte'), the equal sign, or the closing semicolon.

For naming other constants, use the appropriate data type.