Assigning array variables to int variables

I need to control thousands of rgb leds.To make animations I want to assign led numbers(addressable led strip) to arrays.For example `floor[2]room[14]=106` 106 is the number of led,there are many floors and rooms.I want to change floor or room numbers with that way I will make animations. We can say its 92x30 pixel monitor.I tried to create list of floor and rooms but I couldnt make it. I'm new to programming,help please!

Solved with this way `#define LEDNO(FLOOR, ROOM) ((ROOM) + (FLOOR * 92))`

• Are the LEDs in floor/room sequence? I.e., is floor[2]room[15] going to be LED 107?
– Majenko
Nov 12, 2018 at 14:01
• yes,exactly.every floor has 92 rgb,and there is 30 floors. Nov 12, 2018 at 14:02
• Your Arduino has more than 8 K or RAM, right? Nov 12, 2018 at 14:03
• yes I'm using arduino due. Nov 12, 2018 at 14:03
• I'm already controlling all of leds,but I couldnt calibrate them. Nov 12, 2018 at 14:04

You really don't need to maintain a list.

Just calculate the LED index from the location:

``````int room = 14;
int floor = 2;

const int rooms = 92;

int led = room + (floor * rooms);
``````

That is, each floor below the current one (floors and rooms count from 0) is a full row of rooms (92 * floors), and there are "room" extra rooms on this floor to add to it.

You could make a macro:

``````#define LEDNO(FLOOR, ROOM) ((ROOM) + (FLOOR * 92))
``````

Then your LED number is just:

``````int led = LEDNO(2, 14);
``````

Here's an example taken from your code:

``````void floorsup(){

FastLED.setBrightness(brightness);

for(int a=1;a<255;a+=40){
for (int floor = 0; floor < 30; floor++) {
for (int room = 0; room < 92; room++) {
leds[LEDNO(floor, room)].setHSV(a, 255, 255);
}
FastLED.show();
delay(300);
}
for (int floor = 0; floor < 30; floor++) {
for (int room = 0; room < 92; room++) {
leds2[LEDNO(floor, room)].setHSV(a, 255, 255);
}
FastLED.show();
delay(300);
}
for (int floor = 0; floor < 30; floor++) {
for (int room = 0; room < 92; room++) {
leds3[LEDNO(floor, room)].setHSV(a, 255, 255);
}
FastLED.show();
delay(300);
}
}
}
``````
• but with this way I cant light up many leds at the same time Nov 12, 2018 at 14:17
• What does this have to do with how many LEDs you can light up at once? This just gives you an LED number. What you do with that is up to you. I would use it to set an LED colour in the NeoPixel library. I don't think you quite understand exactly what you want to achieve with this.
– Majenko
Nov 12, 2018 at 14:25
• yes but if I wanted to light whole fourth floor its gonna be easy with assigning them number. Nov 12, 2018 at 14:27
• They already have a number. What do you want to "assign"?
– Majenko
Nov 12, 2018 at 14:32
• okay its long but I'm gonna share my code,you will understand what I mean Nov 12, 2018 at 18:54

Something like this would work:

``````#define MAX_FLOORS  92
#define MAX_ROOMS   30

struct floor_str {
int Room[MAX_ROOMS];
} Floor[MAX_FLOORS];
``````

You would then access an individual LED address like:

Floor[2].Room[14] = 106;

• yes,I can take all led numbers from python on this format,but I wasnt know how to assign them.Thank you! Nov 12, 2018 at 14:20
• btw does it should be like `struct floor_str { int room[MAX_ROOMS]; floor[MAX_FLOORS]; } `? Nov 12, 2018 at 14:24
• No. You make a struct of rooms as an array and make an array of them as floors.
– Majenko
Nov 12, 2018 at 14:36
• I already figure out with another way but I would like to learn your method also.Could you check your code again? its giving error. Nov 12, 2018 at 20:04
• The syntax was correct but 'floor' appears to be already defined as something else. An easy solution is to use 'Floor' instead. (edited the solution above) Nov 12, 2018 at 20:38