How to assign a number to a variable

Hi everyone,

sorry for the title which is not clear at all but I had no idea about how to explain it better, which is also the reason why I have not been able to find my answer somewhere else.
So, let’s go to the problem: I want to light several LEDs (more than 30 actually) one after another. My problem is not about lighting them properly (I’m using charlieplexing to do that) but it is about finding an easy way to make them blink one at a time.

My first idea was to do something like this

 digitalWrite(led1, HIGH);
delay(100);
digitalWrite(led1,LOW);
delay(100);
digitalWrite(led2,HIGH);
delay(100);
digitalWrite(led2,LOW);
delay(100);

and so on, which could be done with few LEDs.

Another idea I had was to to this:

int ledList[] = {led1, led2, led3, led4, led5}
ledCount = 5;

 for (int thisLed = 0; thisLed < ledCount; thisLed++){
    digitalWrite(ledList[thisLed], HIGH);
    delay(intervallo);
    digitalWrite(ledList[thisLed], HIGH);

but it becomes a boring work when you have to write so many LEDs in the ledList.
I cannot even use a command like:

digitalWrite(4,HIGH);

(where the pin number 4 corresponds to the led I want to light because I’m using charlieplexing and the variable “led1” for example is an array).

I hope everything is clear :confused: , thank you

"but it becomes a boring work to do to write the ledList with so many LEDs."

WHAT?

Are all the LED pins sequential?

.

int ledList[] ={3,5,6,7,9};

for(int ledCnt=0;ledCnt<5; ledCnt++)
{
  digitalWrite(ledList[ledCnt], HIGH);
  delay (100);
  digitalWrite(ledList[ledCnt], LOW);
  delay (100);
}

Perhaps a look at the use of Charlieplexing in the LOL Shield examples would be useful.

Look how it is done with the LOL (Lots Of Leds) shield.

The shield has 126 LEDS and each can be turned on and off individually or in combination.

The problem is that I cannot simply set a pin HIGH or LOW to turn the led on or off, I wanted to find a way to do do something like this if possible:

for (int ledCounter = 0; ledCounter < pinCount; ledCounter++){
    turn on the led_ledCounter; 
    delay(1000);
    turn off the led_ledCounter;
  }

what I call led_ledCounter is led1 when ledCounter is 1, led2 when ledCounter is 2 and so on

int ledList[] = {led1, led2, led3, led4, led5}
ledCount = 5;

 for (int thisLed = 0; thisLed < ledCount; thisLed++){

use the sizeof() function to return the number of bytes in the array:

for(int thisLed = 0; i < sizeof(ledList)/sizeof(ledList[0]); thisLed++)
{

OK, so look at what UKHeliBob is pointing you to. They do it. See how they do it. Why can't you at least go look at that?

You're right, you can't just write them high and low since they're charlieplexed. Go look at that example to see how to do it with something charlieplexed.

You said that you did not have a problem with the charlieplexing part ??

Anyway, make a two dimensional array that defines all the state of the pins so led 1 is on, led 2 is on etc.

Next, for a given led, you can use a for loop to set those pins to the specified level.