/*
/ How to display number using 4 digits 7-Segment LEDs
/ Very simple and short codes.
*/
// This example is using 7 Segment common anode
// FOR COMMON CATHODE (DP OFF):
//unsigned char digit[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
// FOR COMMON ANODE (DP OFF):
unsigned char digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
// FOR COMMON ANODE (DP ON):
// unsigned char digit[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void setup() {
DDRB |= B00001111; // Pin D8, D9, D10, D11 as output
DDRD = 0xFF; // PORTD (pin D0..D7) all as output
PORTD = 0xFF; // switch off all leds.
}
void loop() {
PORTB = B000001;
for (int d=0; d<=3; d++){
for (int i=0; i<10; i++){
PORTD = digit[i]; // shows digit 0..9
delay(300);
}
PORTD = 0xFF; //switch off all LEDs
delay(500);
PORTB = (PORTB<<1); // change to next digit
}
}