Go Down

Topic: A/D converter with 0 to 1023 binary output (Read 897 times) previous topic - next topic

seth9008

Hi, well, the title say all. I´m trying to do an A/D converter, but i want that the digital conversion be in the digitals pins 2 to 11 in the binary form

For example the minor value 0 is showed in these array of pins
0000000000

if is the max value (1023) is showed

1111111111

i know that the analog pins read 0 to 5V and the max value is 1023=5V

The case is, I want the analog reading be displayed in binary form in an array of 10-bit in the digital pins

any suggestion??????

PD: sorry for my bad english.... :P



InvalidApple

#1
Aug 23, 2011, 04:12 am Last Edit: Aug 23, 2011, 04:56 am by InvalidApple Reason: 1
just some pseudo for you:

if analogue value is above 1000000000:
  minus 1000000000 and turn on pin 11...

if analogue value is above 0100000000:
  minus 0100000000 and turn on pin 10...

... ect

Delta_G

Or to go backwards of that logic (assuming low bit first on pin 2 and high bit on pin 11)


for (int i=0, i<10, i++)
{
digitalWrite(i+2, analog_value & 1);   //bitwise and to 1 so we only take the lowest bit
analog_value = analog_value >> 1;    //shift it one to the right to put the next bit in the low bit.
}


seth9008

mmmm...

well, maybe i did´n explain very well

i know the A/D of the arduino converts 0 to 5V  in the range 0-1023, were 1023 is the max value...

or 4.88 mV for each value of convertion  (1024x0.00488=5V aprox)

if i have 3.5V in the analog input.... 3.5/4.88mV=717.21....

internally in the A/D i have 717.21...or 717....and i want show  this value in an array...

Grumpy_Mike

Quote
internally in the A/D i have 717.21...or 717

You have 717 internally.

It is still not clear what you mean by
Quote
i want show  this value in an array.

An array of what? Do you mean display? The answers given match the question asked.

retrolefty

#5
Aug 23, 2011, 06:21 am Last Edit: Aug 23, 2011, 08:32 am by retrolefty Reason: 1
Quote
and i want show  this value in an array...


Quote
i want that the digital conversion be in the digital pins 2 to 11 in the binary form


What you wish to do is not hard.

Read the analog pin into a variable, then test each bit value of value and turn on or off the digital pin associated with that bit:

       
Code: [Select]
int value = analogRead(A0);
        for (int i=0; i <= 9; i++)
         {
           if (bitRead(value,i))
             {digitalWrite((i+2),HIGH)}
           else
             {digitalWrite((i+2),LOW)}
         }

               

Be sure to use current limiting series resistors with each of the LEDs.

Lefty

Kctess5

I did some thing almost exactly the same as this a while back. The only difference was that I divided it by 4 and then wrote its value to 8 LEDs. It was pretty cool actually. But the bitRead function is the way to go for sure

Go Up