// 7 segment LED display rotates segment, flashes digit 0 & digit counts up
// from 0~9 using direct register access with arrays functions.
// Created by kidkara.
int leddigitsD[11] {B11111100, B0011000, B01101100, B00111100, B10011000,
B10110100, B11110100, B00011100, B11111100, B10111100,
B00000000};
int leddigitsB[10] {B00000000, B00000000, B00000001, B00000001, B00000001,
B00000001, B00000001, B00000000, B00000001, B00000001};
int rotatesegment[12] {B00000010, B00000000, B0000100, B00000000,
B00001000, B00000000, B00010000, B00000000,
B00100000, B00000000, B01000000, B00000000};
void setup() {
DDRD=B11111100;
DDRB=B00000001;
}
void loop() {
for (int i = 0; i < 4; i++) // segments rotate 4x clockwise
{
for (int i = 0; i < 12; i++)
{
PORTD = rotatesegment[i];
PORTB = leddigitsB[0];
delay(50);
}
}
for (int i = 0; i < 4; i++) // segments rotate 4x counter clockwise
{
for (int i = 11; i >= 0; i--)
{
PORTD = rotatesegment[i];
delay(50);
}
}
for (int i = 0; i < 4; i++) // digit 0 flashes 4x
{
PORTD = leddigitsD[0];
delay(200);
PORTD = leddigitsD[10];
delay(300);
}
for (int i = 0; i < 10; i++) // counts up from 0~9
{
PORTD = leddigitsD[i];
PORTB = leddigitsB[i];
delay(1000);
}
}