0

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))

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

2 Answers 2

4

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);
 }
 }
}
answered Nov 12, 2018 at 14:07
11
  • but with this way I cant light up many leds at the same time Commented 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. Commented Nov 12, 2018 at 14:25
  • yes but if I wanted to light whole fourth floor its gonna be easy with assigning them number. Commented Nov 12, 2018 at 14:27
  • They already have a number. What do you want to "assign"? Commented Nov 12, 2018 at 14:32
  • okay its long but I'm gonna share my code,you will understand what I mean Commented Nov 12, 2018 at 18:54
1

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;

answered Nov 12, 2018 at 14:16
5
  • yes,I can take all led numbers from python on this format,but I wasnt know how to assign them.Thank you! Commented Nov 12, 2018 at 14:20
  • btw does it should be like struct floor_str { int room[MAX_ROOMS]; floor[MAX_FLOORS]; } ? Commented Nov 12, 2018 at 14:24
  • No. You make a struct of rooms as an array and make an array of them as floors. Commented 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. Commented 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) Commented Nov 12, 2018 at 20:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.