TheMemberFormerlyKnownAsAWOL:
Don't use pow() for powers of two.
It's a bazooka flyswatter, and just about as accurate.
Hint: if it compiles, the syntax is correct. The semantics need some work.
Great answer, not !
Delta_G:
For powers of 2 just use a bitshift.
for (byte i=0; i<8; i++) {
digitalWrite(i+2, value & (1 << i));
}
That gives me something to consider....
MorganS:
i+2 is a terrible way to address pins. There will always be reasons why you cannot use 8 pins in a row in a real project. Maybe you need pin2's interrupt ability or you need a PWM pin for analogWrite(). Use an array:
const int busPins[] = [2,3,4,5,6,7,8.9];
This is part of some communication bus? How is the data clocked out of the bus? If the receiver sees the first pin change, it may grab the rest of the values before your loop has written them. digitalWrite() is relatively slow. You could look into using a "port write" to write all 8 bits simultaneously.
There is no "clocking" needed. The "receivers" are simple 8-bit "D" type latches. I simply have to present the 8-bit data onto the pins and then pulse the "LE" to them. I can see no reason why "i+2" is a bad way to address the pins. I control when the data is transferred from the "D" inputs to the "Q" outputs with a "Latch Enable" (LE) output.
All that is needed is to pre-code (or build) the data to the data-bus pins, then pulse the "LE" on another pin, in this case pin 10 for the display segment drivers, and pin 11 for the cathode drivers. It does not matter how long it takes to output the data onto the 74HC573 inputs, they are transferred to the "Q" outputs on "LE" transition low to high.
The display board I am testing circuit is here...