// Professor: Christian Bodington // www.conexionelectronica.com // 7-segment display multiplexing int common1 = 0; // set pin 0 to "common1" int common2 = 1; // set pin 1 to "common2" int common3 = 2; // set pin 2 to "common3" int common4 = 3; // set pin 3 to "common4" int segmenta = 4; // set pin 4 to "segmenta" int segmentb = 5; // set pin 5 to "segmentb" int segmentc = 6; // set pin 6 to "segmentc" int segmentd = 7; // set pin 7 to "segmentd" int segmente = 8; // set pin 8 to "segmente" int segmentf = 9; // set pin 9 to "segmentf" int segmentg = 10; // set pin 10 to "segmentg" int refresh = 5; // change this value a see what happend... // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. DDRD = B11111111; // sets Arduino pins 0 to 7 as outputs. DDRB = B11111111; // sets Arduino pins 8 to 13 as Outputs. } // the loop routine runs over and over again forever: void loop() { one(); // call subroutine "one()". digitalWrite(common1, LOW); // Put "0" in PNP base to active the firts 7 segment Display. delay(refresh); // wait for corresponding refresh time set. three(); // call subroutine "three()". digitalWrite(common2, LOW); // Put "0" in PNP base to active the second 7 segment Display. delay(refresh); // wait for corresponding refresh time set. five(); // call subroutine "five()". digitalWrite(common3, LOW); // Put "0" in PNP base to active the third 7 segment Display. delay(refresh); // wait for corresponding refresh time set. seven(); // call subroutine "seven()". digitalWrite(common4, LOW); // Put "0" in PNP base to active the fourth 7 segment Display. delay(refresh); // wait for corresponding refresh time set. } // remember, the 7 segment display is Common Anode, so... if you want turn any segment ON, // you need to put a "0" in the corresponding pin. // // A // - // F| |B // - // G // E| |C // - // D // int one(){ // to display number 1, just put a "0" in: b, c segments. // dcba---- PORTD = B10011111; // -----gfe PORTB = B11111111; } int two(){ // to display number 2, just put a "0" in: a, b, d, e and g segments. // dcba---- PORTD = B01001111; // -----gfe PORTB = B11111010; } int three(){ // to display number 3, just put a "0" in: a, b, c, d and g segments. // dcba---- PORTD = B00001111; // -----gfe PORTB = B11111011; } int four(){ // to display number 4, just put a "0" in: b, c, f and g segments. // dcba---- PORTD = B10011111; // -----gfe PORTB = B11111001; } int five(){ // to display number 5, just put a "0" in: a, c, d, f and g segments. // dcba---- PORTD = B00101111; // -----gfe PORTB = B11111001; } int six(){ // to display number 6, just put a "0" in: a, c, d, e, f and g segments. // dcba---- PORTD = B00101111; // -----gfe PORTB = B11111000; } int seven(){ // to display number 7, just put a "0" in: a, b, andc segments. // dcba---- PORTD = B10001111; // -----gfe PORTB = B11111111; } int eight(){ // to display number 8, just put a "0" in: all segments. // dcba---- PORTD = B00001111; // -----gfe PORTB = B11111000; } int nine(){ // to display number 9, just put a "0" in: a, b, c, f and g segments. // dcba---- PORTD = B10001111; // -----gfe PORTB = B11111001; } int cero(){ // to display number 0, just put a "0" in: a, b, c, d, e and f segments. // dcba---- PORTD = B00001111; // -----gfe PORTB = B11111100; }