newbee question ... defininting pins

First night playing with my Arduino Mega 2560

So, my first program was to blink an led ... I expanded it to blink three.

First part of code identifies pins ....

int BLUE = 3;
int GREEN = 5;
int RED = 6;

OK ... my next lesson was to use the PWM function. Here my first lines of code was ....

#define BLUE 3
#define GREEN 5
#define RED 6

I have been looking all over and can't find an explanation of why I used the two different ways of identifying the output pins.

I "think" the INT stand for integer ??? The explanation on this sites under Variables just says "type" ... what does this mean? Is the #define a different "type" of value. I know it is PWM output so is that what "#difine" means? What other "types" can I define these pins?

Sorry ..... just confused. The projects work but I want to understand the why.

Thanks .... Mike

const byte is one preferred way to declare a type for IO pins, or any other variable that will have a value from 0 to 255.
const keeps it from being changed by the program. Define does also.

So:
const byte ledPin = 3;
for example.
vs
#define ledPin 3

There was a big discussion about why one was better than the other fairly recently if you want to search for it.

I will search for it ... this luck since I am a newbee, it won't be over my head.

So why does the "blink" example program use INT ?

Thanks ..... Mike

Arduino data types.

More Arduino data types.

Arduino define.

So why does the "blink" example program use INT ?

Good question. I think that it is because someone did not want to explain why it is best to use const byte to name a pin. There are a lot of the same sort of things in the tutorials on the web. Things that are just wrong, but have a life of their own and are hard to correct. As you study more you will see that it is best to not rely on only one source of information.

For instance, people that use external pulldown resistors when it is easier to use internal pullups. Probably because the perception that new users may have a hard time with a switch being "on" when LOW. Or the wiring of the contrast pot on character LCDs.

Poor, perhaps lazy, programming habits by whomever wrote the examples I guess.
I use byte wherever I can, save on SRAM & Flash memory.

You guys are awesome!

I will do some reading ....

I am 58, a machinist by trade and build electrical control panels (simple float control to remote cellar connected PLC's) ... and have never touch an Arduino till tonight.

I am one of these "pain in the butt" people who like to do things right ... just ask my wife, it took me 7 years to build a house and we are ""almost" done.

I figure people don't do things for the fun of it ... there must be a reason.

I have a number of projects I hope to build in the coming years ... I want to learn the correct way to write programs.

Thanks so very much for the info !!!!!!!!!!

Mike

PS ... attached is a picture of the last panel I built to remotely control and monitor 12 pumps and report their flow via e-mail each night.

Nice work.

The IDE has a very helpful tool called autoformat. It will indent your code in a standard format. It makes your code more readable.

Thanks! I will check it out.

As you can see, relay logic is not a problem for me ... programming on the other hand .....

The last time I wrote a program was back in the 80's ... in basic.

Heck, when I was in college, we even still had punch cards .... man that was a long time ago!

Thanks !!!!!!!!!

Mike

My first computer class was Fortran Programming in 1973, so yeah, punch cards.