what is format to make digitalWrite variable?

Is it possible to just change the variable in each pass of digitalWrite and if so, what is the format?

 for (i=10;i<14;i++)
  {
    digitalWrite(led(i), HIGH);   // turn the LED on
    delay(10);               // wait for a second
    digitalWrite(led(i), LOW);
    delay(10);

Doing this just returns
led not assigned.
I have tried (led’i’, HIGH); with the same error instruction.
Which format is it?
thanks.

digitalWrite(led(i), HIGH);

Would work if "led" is function returning a pin number and digitalWrite(led[i], HIGH); will work if "led" is an array.

digitalWrite(i, HIGH);

Or make led an array. Use

byte led[ ] = {10, 11, 12, 13,};

for (i=0; i<4; i=i+1){
pinMode (led[i], OUTPUT);
}

and then 

for (i=0;i<4;i++)
  {
    digitalWrite(led[i], HIGH);   // turn the LED on
    delay(10);               // wait for a second
    digitalWrite(led[i], LOW);
    delay(10);
  }

Some names are system names and cannot be used. led might be one of them.
try ledPin if you see some error statements about that.

I have

int i;
int led2=2;
int led3=3;
int led4=4;
int led5=5;
int led10=10;
int led11=11;
int led12=12;
int led13=13;



void setup() {
  // put your setup code here, to run once:
  pinMode(led2,OUTPUT);
  pinMode(led5,OUTPUT);
  pinMode(led10,OUTPUT);
  pinMode(led11,OUTPUT);
  pinMode(led12,OUTPUT);
  pinMode(led13,OUTPUT);
  

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(led2,LOW);
  leds();
  digitalWrite(led2,HIGH);
 /*
 digitalWrite(led3,LOW);
  leds();
  digitalWrite(led3,HIGH);
  digitalWrite(led4,LOW);
  leds();
  digitalWrite(led4,HIGH); 
*/ 
  digitalWrite(led5,LOW);
  leds();
  digitalWrite(led5,HIGH);    
}
void leds()
{
  for (i=10;i<14;i++)
  {
    digitalWrite(led(i), HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(10);               // wait for a second
    digitalWrite(led(i), LOW);

and I get the first digitalWrite line lit up yellow and
‘led’ was not declared in this scope
if I try to compile it.

int led [ ] ={2, 3, 4, 5, 10, 11, 12, 13};

And use the arrya form I showed.

No Bob It still gives ledPIn not recognised

int i;
int led2=2;
int led3=3;
int led4=4;
int led5=5;
int ledPin10=10;
int ledPin11=11;
int ledPin12=12;
int ledPin13=13;



void setup() {
  // put your setup code here, to run once:
  pinMode(led2,OUTPUT);
  pinMode(led5,OUTPUT);
  pinMode(ledPin10,OUTPUT);
  pinMode(ledPin11,OUTPUT);
  pinMode(ledPin12,OUTPUT);
  pinMode(ledPin13,OUTPUT);
  

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(led2,LOW);
  leds();
  digitalWrite(led2,HIGH);
 /* digitalWrite(led3,LOW);
  leds();
  digitalWrite(led3,HIGH);
  digitalWrite(led4,LOW);
  leds();
  digitalWrite(led4,HIGH);  */
  digitalWrite(led5,LOW);
  leds();
  digitalWrite(led5,HIGH);    
}
void leds()
{
  for (i=10;i<14;i++)
  {
    digitalWrite(ledPin(i), HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(10);               // wait for a second
    digitalWrite(ledPin(i), LOW);    // turn the LED off by making the voltage LOW
  }

I have changed it all the way through the program with no improvement?

AWOL I was hoping to do it this way.

So make an array, will duplicate the info of led2, led3, led4, etc.

byte ledPin[] = {2,3,4,5,10,11,12,13,}; // elements 0 to 7   << declare this with the variables

for (i=0; i<8; i=i+1){
pinMode (ledPin[i], OUTPUT);
}

and
for (i=4;i<8;i++) // 10,11,12,13 to switch
  {
    digitalWrite(ledPin[i], HIGH);   // turn the LED on
    delay(10);               // wait for a second               << this is 10mS; use 1000 for 1 sec
    digitalWrite(ledPin[i], LOW);
    delay(10);
  }

OK. is it not possible to make variables able to alter in this way?

No, not in C/C++.

OK well thanks for your prompt replies gents I will assign an array.

you are marked as offline for some reason AWOL ?

I am?

yea the little box under your name on the left is not green ie off line

I'm in stealth moderator mode

[quote author=matelot link=topic=232563.msg1675710#msg1675710 date=1397224145]
Is it possible to just change the variable in each pass of digitalWrite and if so, what is the format?

[code] for (i=10;i<14;i++)
  {
    digitalWrite(led(i), HIGH);   // turn the LED on
    delay(10);               // wait for a second
    digitalWrite(led(i), LOW);
    delay(10);

Doing this just returns
led not assigned.
I have tried (led’i’, HIGH); with the same error instruction.
Which format is it?
thanks.
[/quote]

This will work

code] for (i=10;i<14;i++)
{
digitalWrite(i, HIGH); // turn the LED on
delay(10); // wait for a second
digitalWrite(i, LOW);
delay(10);
[/code]

delay(10);               // wait for a second

In fact that will wait for 0.01 of a second

That's correct, Mike, but the sequence of pins in reply #3 is not continuous.