New Arduino user here.
Theres plenty of tutorials on how to do dec to binary converion to drive LED
a via a shift register, but fewer on how to do dec to binary and drive 8 pins direct.
There`s several ways to do this.
I`ve used this method http://luckylarry.co.uk/programming-tutorials/arduino-programming/arduino-convert-decimal-to-binary/ and it works fine.
But this method
{
int var = get_value_between_zero_and_six();
digitalWrite(11, HIGH && (var & B00001000));
digitalWrite(12, HIGH && (var & B00000100));
digitalWrite(13, HIGH && (var & B00000010));
digitalWrite(14, HIGH && (var & B00000001));
}
from the the old forum looks a lot neater, but I`m having trouble understanding how it works.
digitalwrite can be HIGH or LOW
B0000001 is a bitmask which is used with var, I understand that bit.
So, only digitalwrite if HIGH and (result of var and bitmask) is true?
Thanks.