Go Down

Topic: ADC to 8Bit Pins (Read 2 times) previous topic - next topic

kkshi1123

Hi, i'm new in programming with arduino and i'm having trouble with my proyect, i need to read an analog imput and get an output un binary, but in 8 different pins, meaning that if a have 5 volts on the analog input i should have all 8 pins HIGH ando if i have 0v all mus be LOW, i've been tryin several methods to turn the decimal output of analogRead() into binary and separate it into the outputs with no positive results. What should i do?

PaulS

Quote
What should i do?

You should explain what the "several methods to turn the decimal output of analogRead() into binary and separate it into the outputs" were, and what the code looked like.

So far, all that you have described is that a value of 0 should turn all 8 pins off, and a value of 1023 should turn all 8 pins on. Now, you need to describe what the other 1022 values should do.

If, for instance, you want to turn one pin on when the analogRead() value is between 0 and 127, and two pins on when the value is between 128 and 254, etc., that is trivial. A series of if/else if/else statements will accomplish that.

terryking228

Hi,

See the MAP function... the examples shows mapping 0..1024 (10 bits) to 0..255 (8 bits)

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

PaulS

Quote
See the MAP function... the examples shows mapping 0..1024 (10 bits) to 0..255 (8 bits)

To divide by 4? Don't you think that's overkill?

Steph

Wouldn't the easiest thing be to just bitshift the result two bits to the right?

Go Up