Binary numbers in LEDs

Hi eveyone,

I'm quite struggling with binary.
I have 8 LEDs and a slider potentiometer attached to my arduino.
I want that the LEDs show in binary what value the slider gives.
I already have the numbers in binary but I have no idea how to print these numbers to the LEDs.

How do you print them in leds??

(btw first question on this forum+not native English)

I assume that the pot is connected to an analog input. AnalogRead returns an int (2 bytes) 0 to 1023. 8 bits can represent 0 to 255. So, the first thing is to divide the analogRead value by 4 so it will fit in a byte. Then use the bitRead function to read each bit and write each bit out to the proper pin. See the Reference for descriptions of the bit functions.

Perfect solution from groundfungus.

However, all you need is the bitRead function. No bitClear or bitWrite.

And the code has to loop from 0 thru seven and each value is sent to a different digital output.

Sorry, I realized that and edited my post to remove bitSet and bitClear. Not fast enough, I guess.

You can also use arrays to make the code a lot shorter.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html