Go Down

Topic: Specify "Pin"? (Read 953 times) previous topic - next topic


A little funny question, but, must I specify a pin number using "Pin"?
Code: [Select]
int ledPin = 13;
That should work. But would this?:
Code: [Select]
int led = 13;


Yes it all works. The name is irrelevant as the compiler and linker will simply translate it all to a memory address when it does it's job.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com


You can make your code more easily clear or less clear through your choices of names for variables and functions. 

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts



From a syntax point of view, it doesn't matter.

From a good-practices point of view, it is rather silly to name a variable "pin".  You already know it is a pin, why call the variable that?  Instead, call the variable what that pin is connected to and even better, the function.

"errorLED" or "startButton" or something descriptive like that is much more useful than "int pin = 12;" when you are reading the code.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up