Long story short: I am trying to read a voltage value (0-5VDC) on an analog pin (A0) on Arduino Uno Board and output that voltage value to some drivers through an 8 bits number.
After looking around, it seems like the analogReadResolution (8 ) would be able to help but only on Due or Zero Board. Since I try to keep the hardware to be the same, I wonder if anyone has done some converting before on the Uno or has any hint or clue that can help solve the problem?
Since I try to keep the hardware to be the same, I wonder if anyone has done some converting before on the Uno or has any hint or clue that can help solve the problem?
int tenBitValue = analogRead(somePin);
byte eightBitValue = tenBitValue / 4;
Thanks for all the quick responses and suggestions.
Since my signal doesn't have to be super accurate, I think the simple trick helped solve the problem by just dividing the 10-bit number to 4 in order to obtain the 8-bit number.
Yep, by far the best solution. You can also shift the value 2 places to the right and drop the last two digits.
Don't add the 2 to compensate for rounding! That only gives you an offset here. In a 8bit ADC (with 5V ref) the value 0b11111111 will be from the voltage 4.98046875V. And that's the same voltage on a 10bit ADC (again with 5V ref) when it outputs 0b1111111100. So just drop the last two bytes bits (divide it by 4 or shift by 2, doesn't matter).
septillion:
Yep, by far the best solution. You can also shift the value 2 places to the right and drop the last two digits.
Don't add the 2 to compensate for rounding! That only gives you an offset here. In a 8bit ADC (with 5V ref) the value 0b11111111 will be from the voltage 4.98046875V. And that's the same voltage on a 10bit ADC (again with 5V ref) when it outputs 0b1111111100. So just drop the last two bytes (divide it by 4 or shift by 2, doesn't matter).