system
December 17, 2010, 1:09am
1
Hi - I have multiple LED's set up for turning on and off and stuff.
is it possible to create separate ints for them (EG: int blue; int red; int green;) but then also to have an int for all of them to save space and time? EG: int all; ?
I attempted by writing
int all;
void setup()
all = 5;
all = 6;
all = 7;
but then all that happened was 5 lit up.
Thanks!
system
December 17, 2010, 1:21am
2
is it possible to create separate ints for them
Yes.
but then also to have an int for all of them to save space and time? EG: int all;
No.
You could put the pin numbers in an array, and loop through the array to turn them all on or off.
system
December 17, 2010, 1:30am
3
that would work, I didn't think of that - thanks
system
December 17, 2010, 11:15pm
4
While you can't have an int that sets them all, you can use a function that sets the other ints.
So instead of:
int all;
void setup()
{
all = 5;
}
You would have something like:
int red = 0;
int green = 0;
int blue = 0;
void setup()
{
SetAll(5);
}
void SetAll(int value)
{
red = value;
green = value;
blue = value;
}
Note that this will only work for global variables, but that is fine if you are following Arduino standards.