int i; // counter variable
int j; // pgm outputs codes 00000 to 11111 in portd 2-7bits
void setup()
{
DDRD = DDRD | B11111100; // set direction bits for pins 2 to 7, leave 0 and 1 untouched //(xx | 00 == xx) same as pinMode(pin, OUTPUT) for pins 2 to 7
Serial.begin(9600);
}
void loop()
{
for (i=0; i<64; i++)
{ // 6 bits manipulated 0 to 63
PORTD = PORTD & B00000011; // clear out bits 2 - 7, leave pins 0 and 1 untouched (xx & 11 == xx)
j = (i << 2); // shift variable up to pins 2 - 7 - to avoid pins 0 and 1
PORTD = PORTD | j; // combine the port information with the new information for LED pins
Serial.print("PORTD in BINary="); // debug to show masking
Serial.println(PORTD, BIN); // debug to show masking
delay(2000);
}
}