led light up dimly

hi there,

im learning arduino programing, and came across a rly annoying thing. im sure my programing skill is the reason i have this problem, but i cant find an answer on the internet about my problem so im hoping to get hlp here.

so i wanted to make a led chaser program and started off with a simlpe code... defined all the outputs i wanted (pinmode(3, OUTPUT), pinmode(4, OUTPUT)...), in the loop section did the digilalwritefunction and delay for every led... worked well. then i said, ok, i dont want to type the same thing for every output separately... so i made a loop... i used while, but i dont thing it matters here what type of loop i chose.

this is the code:

int pin;

void setup() {
pinMode(pin, OUTPUT);

}

void loop() {
pin = 3;
while (pin<=6)
{
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
pin++;

}
}

when i uplaoded the code to my arduino uno, it did what i wanted, but the leds werent lighting up as much as they should (tried smaller resistors and everything). the board isnt damaged, nor the uC... everything works well with examples, with the previous code also.

what am i doing wrog? i know the is in the setup funcition, but i cant figure out why it wont do as i told him

pls help me and thanks in advace

You are missing a loop in setup() which sets the pins you are using to output. At the moment you only set 'pin', which is zero at best and undefined at worst.

you should set all your LED output pins to OUTPUT.
Not just the "pin" in setup.
Use a for loop to run through all pin numbers.

You need a delay after the LOW write to the LED, otherwise you will only see the LED lighting up, it wont blink.

Yes, as dannable said, set all the desired pins (3 to 6) to OUTPUT mode:

void setup() {
for (byte x = 3; x<=6; x=x+1){
pinMode(x, OUTPUT);
}
}

wow... what noob i am :smiley:

this is how it looks now

int pin = 3;

void setup() {
while (pin <= 6)
{
pinMode(pin, OUTPUT);
pin++;
}

}

void loop() {
pin = 3;
while (pin <= 6)
{
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
pin++;

}
}

@anders... i didnt want them to blink, and i use the while loop more often (i dont realy know the diference between while and for loops), the while loop is just more natural to me

super fast reply and fixed my problem... ty so much dannable and anders <3

u too CrossRoads :wink: