//3 Bit Binary Down Counter, counts 7-0 and resets
int counter; //sets up counter variable
int code; //sets up code variable
void setup()
{
DDRD = DDRD | B11111100; //sets pins 2-7 as outputs, cannot use pins 0 and 1
Serial.begin(9600); //starts Serial Monitor
}
void loop() //a counter 7 to 0
{
for(counter=7; counter<8; counter--) //counts down 7-0
{
if (counter>=0) //counts down if counter is more than 0
{
PORTD = PORTD & B00000011; //sets bits 2-7 to zero, leave 0 and 1
code = (counter<<2); //shifts variable to pins 2-7, to avoid pins 0 and 1
PORTD = PORTD | code; //or's port info with code variable
Serial.println(PORTD, BIN); //displays count in binary
Serial.println(counter); //displays count in decimal
delay(500); //sets half a second between steps
}
else
{
PORTD = PORTD & B00011111; //resets the counter once 0 is reached
}
}
}