This might be a silly question but i have no idea how to do it.
How can i put these pins:
#define AXPin 3
#define AYPin 4
#define AZPin 5
and place them all under the name "acc".
I tried:
int acc [3]= {cGyroAXPin, cGyroAYPin, cGyroAZPin};
but that doesnt work when i use "acc" later in my code.
All i want is that when i call "acc" [eg acc.readAccel] all the pins inside the "acc" are the ones working.
Can anyone help me please?
Thanks a lot
You are on the right track in defining an array of pin numbers. Where you are going wrong is in your attempted use of that array.
All i want is that when i call "acc" [eg acc.readAccel] all the pins inside the "acc" are the ones working.
The acc variable is an array. You can not "call" an array. You could pass the array to the readAccel() function.
Right, so i cant place my pins in an array to place them all together?
How can i pass the array to my function then? Im not sure how to do this :s
Right, so i cant place my pins in an array to place them all together?
Yes, you can.
How can i pass the array to my function then? Im not sure how to do this
Define the function to take an array as an argument:
void functionWithArrayArg(int pinNumbers[3])
{
}
would something like this work (or look better to you?) )
struct ACC {
const char AXPin=3;
const char AYPin=4
const char AZPin=5
} acc;
//using it
X = analogRead(acc.AXPin);
I prefer the . notation over arrays for things like these, but it's my taste. Give it a go and see if you can get it compiled.