Pages: [1]   Go Down
Author Topic: A/D converter with 0 to 1023 binary output  (Read 605 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.... smiley-razz


Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 219
Have you tried turning it off and on again?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 22, 2011, 09:56:55 pm by InvalidApple » Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 645
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
}

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 504
Posts: 31328
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16459
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: August 23, 2011, 01:32:43 am by retrolefty » Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 193
The people the people they see me and they know
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: