Cant get my code to handle my array properly(i think)

hey guys…so straight to the point. my code is supposed to read from a potentiometer and map that value to a new value from 0 - 10. then display the value on a 10 segment bar graph that should fill from one side. the first for loop seems to work and does what its supposed to but the second for loop(intended to turn the leds thats not being used low) does not work…so the graph displays the increase but not the decrease. esentially, the code is set to first turn on the leds from 0 up to the mapped pot value(int level) and then it sets the pins after that specific value to low (so i to 0=HIGH and i+1 to 10=LOW). also i have this “glitch” where the first LED is always on but dim but im not too worried about that right now. heres the code…and thanks in advance!!

int barPins[10] = {2,3,4,5,6,7,8,9,10,11};
int potPin = A0;
int i;

int level;												//Mapped level of pot (1-10)

void setup()
{

	pinMode(barPins[1], OUTPUT);
	pinMode(barPins[2], OUTPUT);
	pinMode(barPins[3], OUTPUT);
	pinMode(barPins[4], OUTPUT);
	pinMode(barPins[5], OUTPUT);
	pinMode(barPins[6], OUTPUT);
	pinMode(barPins[7], OUTPUT);
	pinMode(barPins[8], OUTPUT);
	pinMode(barPins[9], OUTPUT);
	pinMode(barPins[10], OUTPUT);
	pinMode(potPin, INPUT);

}

void loop()
{

	level = map (analogRead(potPin),20,1023,0,10);

	for(i=0; i<=level; i++)
	{
		digitalWrite(barPins[i], HIGH);
	}

	for(i=0; i<=10; i++);
	{
		digitalWrite(barPins[i], LOW);
	}

}

ps sorry for the formatting, im using a plugin for visual studios to Write and upload sketches

	pinMode(barPins[1], OUTPUT);
	pinMode(barPins[2], OUTPUT);
	pinMode(barPins[3], OUTPUT);
	pinMode(barPins[4], OUTPUT);
	pinMode(barPins[5], OUTPUT);
	pinMode(barPins[6], OUTPUT);
	pinMode(barPins[7], OUTPUT);
	pinMode(barPins[8], OUTPUT);
	pinMode(barPins[9], OUTPUT);
	pinMode(barPins[10], OUTPUT);

Array indices start at 0.

	for(i=0; i<=10; i++);

You are turning off all 11 of your 10 pins.

Do not start the second loop with I=0 It needs to be started at I = level

sorry i forgot to change that back in the second loop (after vigorously figiting trying to determine the cause). i initially had it as "i=level+1" because i only want the leds after level to go off(if level = 5 then 1-5 high and 6-10 low) but i tried it as i = level as well...still nothing...and thanks for telling me about the setup error paul but i corrected it and still nothing.

How do you expect to get help if you don'tost the code you are actually having trouble with. So post what you have now with the errors corrected and we will have another look at it.

Again…sorry about that i missed putting that back before i posted but this is the code again

int barPins[10] = {2,3,4,5,6,7,8,9,10,11};
int potPin = A0;
int i;

int level;												//Mapped level of pot (1-10)

void setup()
{
	pinMode(barPins[0], OUTPUT);
	pinMode(barPins[1], OUTPUT);
	pinMode(barPins[2], OUTPUT);
	pinMode(barPins[3], OUTPUT);
	pinMode(barPins[4], OUTPUT);
	pinMode(barPins[5], OUTPUT);
	pinMode(barPins[6], OUTPUT);
	pinMode(barPins[7], OUTPUT);
	pinMode(barPins[8], OUTPUT);
	pinMode(barPins[9], OUTPUT);
	pinMode(potPin, INPUT);

}

void loop()
{

	level = map (analogRead(potPin),20,1023,0,10);

	for(i=0; i<=level; i++)
	{
		digitalWrite(barPins[i], HIGH);
	}

	for(i=level+1; i<=10; i++);
	{
		digitalWrite(barPins[i], LOW);
	}

}

oh also, i tried doing a serial write of i in the second for loop and i always comes back as 11 for some reason (i dont know if that is a legitimate test but just giving all the info i can)

	for(i=level+1; i<=10; i++);
	{
		digitalWrite(barPins[i], LOW);
		Serial.println(i);
	}

and i did initiate serial communication in setup incase you ask. thanks

	for(i=level+1; i<=10; i++);

You can’t turn the 11th of 10 LEDs off.

okay but even so, if i change it to “i=level”. the same thing happens. ive tried taking out the second for loop and replacing it with low digital writes for each pin and it works somewhat but at half brightness because its causing the leds to be off half of the time. point being it kind of works if i take the for loop out so the problem should lie within that?

int barPins[10] = {2,3,4,5,6,7,8,9,10,11};
int potPin = A0;
int i;

int level;												//Mapped level of pot (1-10)

void setup()
{
	pinMode(barPins[0], OUTPUT);
	pinMode(barPins[1], OUTPUT);
	pinMode(barPins[2], OUTPUT);
	pinMode(barPins[3], OUTPUT);
	pinMode(barPins[4], OUTPUT);
	pinMode(barPins[5], OUTPUT);
	pinMode(barPins[6], OUTPUT);
	pinMode(barPins[7], OUTPUT);
	pinMode(barPins[8], OUTPUT);
	pinMode(barPins[9], OUTPUT);
	pinMode(potPin, INPUT);
	Serial.begin(9600);

}

void loop()
{

	level = map (analogRead(potPin),20,1023,0,10);

	for(i=0; i<=level; i++)
	{
		digitalWrite(barPins[i], HIGH);
	}

		digitalWrite(barPins[0], LOW);
		digitalWrite(barPins[1], LOW);
		digitalWrite(barPins[2], LOW);
		digitalWrite(barPins[3], LOW);
		digitalWrite(barPins[4], LOW);
		digitalWrite(barPins[5], LOW);
		digitalWrite(barPins[6], LOW);
		digitalWrite(barPins[7], LOW);
		digitalWrite(barPins[8], LOW);
		digitalWrite(barPins[9], LOW);
}

please note i only used the above for testing. im aware its not a feasible solution.

The for loop you had was fine, but you have to use <10, not <=10.

oh yes...but...still not working...this seems futile...sorry to have been such a nag

oh yes…but…still not working…this seems futile…sorry to have been such a nag

No problem, but you do need to post your current code.