ATtiny85 shiftout
Jump to navigation
Jump to search
In an attempt to port some code originally written for Arduino I came across a function that doesn't seem to be supported on AVR-GCC. I hope I just haven't found the library yet but in any case, here's some code to produce the same function.
#define HIGH 1
#define LOW 0
void shiftOut(byte dataPin, byte clockPin, byte bitOrder, byte value)
{
int i;
for (i = 0; i < 8; i++)
{
if (bitOrder == LSBFIRST)
{
digitalWrite(dataPin, !!(value & (1 << i)));
} else {
digitalWrite(dataPin, !!(value & (1 << (7 - i))));
}
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
See also: