//Parallel and Serial output demonstration from Arduino digital I/O pins
const int serialLED = 13;
void setup() {
DDRD = DDRD | B11111100; //UNSAFE to use pins 0 and 1 due to the ATMega using it for programming, but this syntax is safer
pinMode(serialLED, OUTPUT);
}
void loop() {
int ser; //Serial shift register
for(int i = 0; i < 255; i++){
PORTD = i; //output 8-bit binary representation to LEDs (on pins 0-7)
ser = i; //copy current number to serial shift register
for (int j = 0; j < 8; j++){
digitalWrite(serialLED, ser&1); //output current bit in "low order" position (1s position)
ser >>= 1; //shift the serial output byte
delay(200);
}
}
}