arduino array[]

Is it possible to make array values like this: int array[3] { 1, 2, 3&4 }; so the third value would be both 3 and 4 at the same time, using this I could make two leds light up at the same time easier.
9 Replies
Maverick
Maverick5w ago
You can derive many numbers from one value using math of some sort. For example:
int array[3] = {1, 2, 7};
pinMode(array[2] - 3, OUTPUT);
pinMode(array[2] - 4, OUTPUT);
digitalWrite(array[2] - 3, HIGH);
digitalWrite(array[2] - 4, HIGH);
int array[3] = {1, 2, 7};
pinMode(array[2] - 3, OUTPUT);
pinMode(array[2] - 4, OUTPUT);
digitalWrite(array[2] - 3, HIGH);
digitalWrite(array[2] - 4, HIGH);
TheStudier
TheStudierOP5w ago
hmm wut
Maverick
Maverick5w ago
This turns on LEDs attached to pin 3 and 4.
TheStudier
TheStudierOP5w ago
oh okay thank you
Maverick
Maverick5w ago
Just for fun, here is another way you could do something like this: https://wokwi.com/projects/439078942615205889
TheStudier
TheStudierOP5w ago
I try to avoid libraries as a beginnre
Maverick
Maverick5w ago
Not really a library exactly, just a header file and a .cpp file that I wrote to keep the .ino file less cluttered.
TheStudier
TheStudierOP5w ago
okey
jim lee
jim lee5w ago
You can drive an aray of pointers then do anything you can dream up with them. Say you make a class of number sets. Then derive an array of pointers to this kind of class. Each array slot could have a competely different set.

Did you find this page helpful?