Go Down

Topic: Why use int instead of byte for pin numbers? (Read 3 times) previous topic - next topic

stoopkid

Why do we use:
Code: [Select]
int led = 13;
instead of
Code: [Select]
byte led = 13;

If you would never need to define more than 256 pins, why use the extra space for int? Is there a reason?

Thanks.


stoopkid

I'm thinking that's the best idea unless there is something I'm missing. Which is likely.

It's just that's the way it's done in most examples, even the arduino default ones. So I figured there may be a reason.

CrossRoads

I always use byte, not int.

sometimes even
const byte  ledPin = 13;

but generally not, because I don't allow ledPin to change value in the software.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

MarkT

People often use int to avoid having to explain more datatypes - byte takes less space and
is perfectly reasonable.  const declarations allow the compiler to optimize the variable away
with luck. Also
Code: [Select]

#define led_pin 13

is fine and avoids introducing any variable.
[ I won't respond to messages, use the forum please ]

Go Up