loading LEDs?

i want to make LEDs "load up" and then don't turn off until i press a button, how do i do that? code would be appreciated

thx//Anto2

i want to make LEDs "load up"

What does that mean?

i mean that i got for example 8 LEDs that slowly light up one by one, then when all lights are on they stay on until i press a button then they restart.

int button = 3;
int led = 11;


void setup() {
pinMode(led, OUTPUT);
}

void loop() 
{
if(digitalRead(button)==HIGH)
{
  for(int i; i<255; i++)
  {
     if(digitalRead(button)==LOW)
       {
         break;
       }
      analogWrite(led, i);
      delay(3);
  }
  while(digitalRead(button)==HIGH)
  {
    //Do nothing
  }
}
else
{
  digitalWrite(led,LOW);
}
}

This should work for one LED.

Make sure you use a 10K pullup resistor with your switch:

Learn about pullup resistors at Pull-up Resistors - learn.sparkfun.com

for(int i; i<255; i++)

Close.
No cigar.

anto2:
i mean that i got for example 8 LEDs that slowly light up one by one

Given there are not eight PWM pins on a UNO, that could be tricky.

You could easily manage two LEDs using soft PWM, the rest on hardware.

i<=255

is that better @Groove?

Solder_Soldier:

i<=255

is that better @Groove?

Nope

Only one led at a time needs to be fading. The others are either on or off. So you might as well do all the fading in software.

PaulRB:
Only one led at a time needs to be fading. The others are either on or off. So you might as well do all the fading in software.

My sentiments entirely.

I think that you would need to use an 8 bit shift register and pwm on the output enable pin while shifting 10000000 or 00000001 right or left respectively.

Solder_Soldier:
I think that you would need to use an 8 bit shift register and pwm on the output enable pin while shifting 10000000 or 00000001 right or left respectively.

Why do you think you need extra hardware?

Solder_Soldier:
I think that you would need to use an 8 bit shift register and pwm on the output enable pin while shifting 10000000 or 00000001 right or left respectively.

And you did not read reply #2, did you? :roll_eyes: