Wanted to know how to control array of LEDs using potentiometer. e.g. : for a certain pitch on potentiometer only one LED lights up and so on
Put the LEDs in an array. Choose the array index to light based on the analog value read by the potentiometer.
Just buy one of these:
Look at the analogRead() examples in the IDE. You should also look at the map() function since you will need that to map your analog value (0-1023) into the range of how many LEDs you have in our array
How many LEDs do you have?
What type of LEDs are they?
How are they wired up?
for a certain pitch on potentiometer only one LED lights up and so on
Understood the first part but what is the "and so on"?
More specific help can be given with more information but generally:-
The analogue input reading returned a number between 0 and 1023, so divide 1024 by the number of LEDs you have, to get your steps, call this the step number. Then read from the pot and divide the reading by the step number. This gives you the LED number to turn on.
Here is example code to illustrate what Grumpy_Mike said.
const byte ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
const byte analogInPin = A0;
const unsigned int increment = 1023 / sizeof(ledPins);
void setup()
{
Serial.begin(115200);
for (unsigned int n = 0; n < sizeof(ledPins); n++)
{
pinMode(ledPins[n], OUTPUT);
digitalWrite(ledPins[n], HIGH);
delay(200);
}
for (unsigned int n = 0; n < sizeof(ledPins); n++)
{
digitalWrite(ledPins[n], LOW);
}
}
void loop()
{
static unsigned long timer = 0;
unsigned long interval = 500;
if (millis() - timer >= interval)
{
timer = millis();
int analogIn = analogRead(analogInPin);
Serial.print("pot value = ");
Serial.println(analogIn);
unsigned int ledToLight = analogIn / increment;
Serial.println(ledToLight);
for (unsigned int n = 0; n < sizeof(ledPins); n++)
{
digitalWrite(ledPins[n], LOW);
}
digitalWrite(ledPins[ledToLight], HIGH);
}
}