Setting multiple LEDs to high simultaneous within a pattern

Hi there,

I am new to coding in general and bought an UNO v 3.

I am currently writing a sketch making use of a 10 led array with common cathode and using pins 2 through 11. I am able to get a 50 + pattern going with one pin set as high at a time.

What I am trying to achieve

I want all 10 x LEDs to be set as High within the pattern (so far the pattern only have 1 pin set as high at a time)

I have spent many hours looking for an example of how to get all 10 pins as high with no joy. (creating a flashing effect, all 10 x LED at the same time strobe effect)

There are also so many topics on this wonderful forum that I actually got lost.

I started by using the example sketch within the library provided and it is working 100%, I just can't figure out how to go ahead from here to incorporate the desired effect to the sketch.

Any help will be greatly appreciated.

Kind regards

Gert

Please, if any more info is needed to understand my question, don't hesitate to ask.

there is more then the forum..
seen this Arduino - Home ?
i think you should try to figure it out, to learn arduino programming.
If you can get one led, more shouldnt be complex.

patterns you might do with some if(yourtest here){yourcode here} constructions.

Hi there PGTBOOS,

Thank you for your reply. This is the first time I asked for help at all regarding coding. I have been trying this code for the better part of 3 days. I want to learn the hard way as that is the only way I learn. (just need a little guidance in the coding).

Just another question if possible...

Is it possible to merge the two codes (single LED pattern and single / multiple LED fade)?

Kind regards

Gert

PS: I will not give up, it's just getting a little frustrating learning a new way of life without a nudge every now and then

If you have already used pinMode to declare the pins at OUTPUTs, you can do this:
PORTC = B11111111;
to set the pin high at one time for that port.
Much faster than 8 digital writes.
With 11 pins, you will have at least 2 ports in use.
Figure out which ports you are using.

If you want to set only certain bits high:
PORTC = PORTC | B00001100; // set bits 2,3 high, leave rest alone

If you want to clear only certain bits low:
PORTC = PORTC & B11110011; // clear bits 2,3 low, leave rest along

Please, if any more info is needed to understand my question, don't hesitate to ask.

Here I am not hesitating to ask you to post code.

Ok, click Modify & repaste the code by highlighting in the IDE, then do CTRL-C to copy it and CTRL-V to paste it in.
Its not readable with all the color notations in there.

Couple of things:

  1. Don't use "Copy for Forum" in the IDE and "code" tags in the forum. Just copy and paste your code. Sound silly. It is. But everyone will appreciate it. (or change your "code" tags to "quote" tags)

  2. Do you actually need to turn on multiple pins at the same time? For visual effects, digitalWrite() with for loops is probably easier to implement and fast enough to fool the slow humans that see them.

WoW, Thank you all for the support and input.

the first sketch (I know that it is a mess, will clean up soon) is 10 x led in a heart formation, pin 2 - 11.
I did the heart to involve my 7 year young daughter.

int timer = 100; // The higher the number, the slower the timing.
int ledPins[] = {
2, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11,
2, 11, 3, 10, 4, 9, 5, 8, 6, 7,
2, 4, 6, 8, 10, 11, 9, 7, 5, 3,
2, 7, 11, 7, 3, 7, 10, 7, 4, 7,
9,
7, 5, 7, 8, 7, 6, 7, 2, 7, 3,
8, 4, 9, 5, 10, 6, 11, 7, 2, 8,
3, 9, 4, 10, 5, 11, 6, 2, 7, 2,
2,
2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7,
7, 8, 8, 9, 9, 10, 10, 11, 11, 2,
2,
}; // an array of pin numbers to which LEDs are attached (7 < 10 - GFWORX)
int pinCount = 96; // the number of pins (i.e. the length of the array)

void setup() {
int thisPin;
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}

void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);

}

// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}

Thank You for the tip Crossroads and JAMES C4S.

Thank you to the creator of the code, I only added pin configuration in order to teach my self how to modify the code.

Second is a Sketch from the library as well. I unfortunately did not save the re worked code earlier this evening.

This is the sketch that i tried to modify for the use of 10 x LED.
I would like to set multiple pins high, both in the flashing pattern and in the fading pattern, at the same time / within the same sketch, with both fast and slow speed. (Merge the two functions of the code, flash / fade, as well as change timing of individual patterns within the same code.

i hope that this make sense to you.

int ledPin = 9; // LED connected to digital pin 9

void setup() {
// nothing happens in setup
}

void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

I started at the top of the sketch and added pin 2 - 11 = 10 x LED
run the code and worked on the error codes all the way to the end of the sketch.
I eventually got a java error.

I do apologize for the Essay.

Once again, thank You all

Kind regards

Gert

CrossRoads:
If you have already used pinMode to declare the pins at OUTPUTs, you can do this:
PORTC = B11111111;
to set the pin high at one time for that port.
Much faster than 8 digital writes.
With 11 pins, you will have at least 2 ports in use.
Figure out which ports you are using.

If you want to set only certain bits high:
PORTC = PORTC | B00001100; // set bits 2,3 high, leave rest alone

If you want to clear only certain bits low:
PORTC = PORTC & B11110011; // clear bits 2,3 low, leave rest along

Thank You.

I will have to take some time to study the above tip. I have not reached, possibly skipped, this section Crossroads.