How to define sectors???

Hi!
I am making led costume project with Arduino and I want to know in programming - how to define different costume sectors to make programming faster and sketch shorter??? Example, how to define all leds which belongs to left arm or chest, right leg, shoes, gloves etc.?????

Hmm... from what I understand, do you want to turn on a few LEDs at the same time?

If it is this, there is a fast and very light way. Arduino UNO divides its I/O by ports (B, C, D).

Here's an image that explains it better...

As you can see, if you want to turn on for example 8 LEDs at the same time, you can use all the PORTD pins, which are pins 0-7.

With this code you can turn on 8 LEDs at the same time:

``````void setup() {
DDRB = 0B11111111; // 0-7 OUTPUT
}

void loop() {
PORTB = 0B11111111; // 0-7 HIGHT
delay(1000);
PORTB = 0B00000000; // 0-7 LOW
delay(1000);
}
``````

Be careful with pins 0 and 1, as you are using them you will not be able to use the Serial.print

This is just a vague example, this I think is the fastest way to activate a pin or sector of pins, and it does not spend almost any memory, but to do what you want (activate certain LEDs of a PORT, since I imagine you don't want to turn on 8 pins at the same time) you will have to know how to use and modify the PORT register to turn on one pin at a time.

The OP didnâ€™t mention how the LEDs were connected (could be WSxxxx type devices), so launching into port manipulation could be premature.

I imagine they are just normal LEDs and he is trying to do some animation with them, and he realized that using digitalWrite wastes a lot of memory and some time. Using the PORT will save you a lot of memory, although you could go to some algorithm to do the animation, but I don't think it uses an algorithm.

l-stars:
Hi!
I am making led costume project with Arduino and I want to know in programming - how to define different costume sectors to make programming faster and sketch shorter??? Example, how to define all leds which belongs to left arm or chest, right leg, shoes, gloves etc.?????

Which Arduino?
What LED hardware?

If you are using NeoPixels, I have a library that breaks a string of them into sectors just as you say. Each is programmed independently from the rest. Patterns can be repeated as well.

-jim lee

I want to know in programming - how to define different costume sectors to make programming faster and sketch shorter

• should post your code in codetags.
• make a schematic drawing which groups of LEDs you currently have.

One option could be to use arrays to store the LED information and a function which activates whatever array you are handing over

something like

``````const byte rightArm[]{2,4,34,42,121};
const byte leftFoot[]{1,33,37,39,43};
...
setLeds(rightArm, ON);
``````

ToddL1962:
Which Arduino?
What LED hardware?

Arduino UNO and Arduino Mega 2560.
WS2815 LED strips.

noiasca:

• should post your code in codetags.
• make a schematic drawing which groups of LEDs you currently have.

One option could be to use arrays to store the LED information and a function which activates whatever array you are handing over

something like

``````const byte rightArm[]{2,4,34,42,121};
``````

const byte leftFoot{1,33,37,39,43};
...
setLeds(rightArm, ON);

Please, can You put some colors and delays in this code, so I know what its really looks like!