xl97
1
Hi gang-
I have a question on using arrays.
normal usage:
byte buttons[] = {5, 6, 3, 9};
can it be done like this instead:
const int safetyPin = 5;
const int normalPin = 6;
const int autoPin = 3;
const int reloadPin = 9;
byte buttons[] = {safetyPin, normalPIn, autoPin, reloadPin};
I guess an arrays of variables? or references to pin(s)?
this way I can also refer to them by pin name else where..etc..
Thanks
Yes
int *i_Array[] = { &safetyPin, &normalPIn, &autoPin, &reloadPin};
notice the int pointer type, not a byte, declare the constants as bytes to use byte*
EDIT: this will use more ram than your first method.
xl97:
can it be done like this instead:
const int safetyPin = 5;
const int normalPin = 6;
const int autoPin = 3;
const int reloadPin = 9;
byte buttons[] = {safetyPin, normalPIn, autoPin, reloadPin};
Try it and see? Apart from the typo on normalPIn, that compiles and should work.
Even this, since you are using constants:
const byte buttons[] = {safetyPin, normalPin, autoPin, reloadPin};
The OP did not say anything about pointers.
Ah, except the thread title of course.
My response was to the actual post, I ignored the thread title.
xl97:
Hi gang-
I have a question on using arrays.
normal usage:
byte buttons[] = {5, 6, 3, 9};
can it be done like this instead:
const int safetyPin = 5;
const int normalPin = 6;
const int autoPin = 3;
const int reloadPin = 9;
byte buttons[] = {safetyPin, normalPIn, autoPin, reloadPin};
I guess an arrays of variables? or references to pin(s)?
this way I can also refer to them by pin name else where..etc..
Thanks
Learn about enumerators (enum), they can also help you keep your code straighter.
xl97
9
thanks guys..
whre can I learn about: (enum)?
I didnt see it listed here: Arduino - Home
Am I allowed to use any "C" code or something?
I found this:
http://arduino.cc/playground/Code/Enum
but how to use it and why didnt really click yet.. =(
Your intention could be expressed using enums something like this:
enum MY_PIN_SET{
safetyPin = 5,
normalPin = 6,
autoPin = 3,
reloadPin = 9,
};
const byte buttons[] = {safetyPin, normalPin, autoPin, reloadPin};