What should i do?
See the MAP function... the examples shows mapping 0..1024 (10 bits) to 0..255 (8 bits)
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?
Hi, I think the purpose is to help the OP accomplish what he wants to do. We may think in binary, and see shift as the obvious solution, but newbies don't...
he wants to light up his LEDs in sequence.
int value=analogRead(0); // read the portvalue = value >> 2; // go from 10 bits to 8 bitsPORTD = lowByte(value); // set digital pins 0 to 7 accordingly
Wouldn't the easiest thing be to just bitshift the result two bits to the right?
I'd like to think that the compiler's strength-reduction optimization will replace a divide by a constant four with a shift right by two. Easier to read.
get the decimal number form analogRead and turn it to binary
...if the input voltage is 2.5 volts, tha output should be 00001111, 5v 11111111, 0v 00000000...
bargraph9 output states:000000000000000100000011000001110000111100011111001111110111111111111111
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16