int i; // counter variable
int j; // pgm outputs codes 00000 to 00111 in portd 2-4 bits
void setup(){
DDRD = DDRD | B00011100; // set direction bits for pins 2 to 4, leave 0 and 1 untouched
//(xx | 00 = xx) same as pinMode(pin, OUTPUT) for pins 2 to 4
Serial.begin(9600);
}
void loop(){
for (i=7; i>0; i--)
{ // 3 bits manipulated 0 to 7
PORTD = PORTD & B11100011; // clear out bits 2 -4, 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("Counter variable i="); // debug to show masking
Serial.println(i);
Serial.print("PORTD in BINary="); // debug to show masking
Serial.println(PORTD, BIN); // debug to show masking
delay(1000);
}
}