10 bit led display from potentiometer

Dear experts,

I am facing a problem to display 10bit data to 10 pcs led read by potentiometer. Do you have a way to program it.
Currently I am using arduino nano.
I mean that when the data read by potentiometer is 3 so led 1 and 2 should be lit. When the data are 10 so the binary data are 1010 so led 1 is off, led 2 is on, led 3 is off, led 4 is on.

Thanks in advance

Hi Alirh,

You can simply convert your decimal number in base 2 number implementing the following pseudocode:

number = your positive integer ;

while (number > 0 )
{
  bit      = number mod 2 ; 
  quotient = number div 2 ;
  number = quotient ;
}

Use the bit together with the function digitalWrite(pin, bit) to turn on/off your led.
Remember that the first bit you obtain is the least significant in you led sequence.

Example:

number 6 (in base 2 is 110)

6 mod 2 = 0 - 6 / 2 = 3 --> PIN0 = LOW
3 mod 2 = 1 - 3 / 2 = 1 --> PIN1 = HIGH
1 mod 2 = 1 - 1 / 2 = 0 --> PIN2 = HIGH

Remember to configure pins as OUTPUT.