• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Better 7-segment timer

    Blog entry posted in 'Projects', October 18, 2015.

    Made better timer, now that there is better time between digits (thanks for pointing that detail yesterday!)
    7-segment is driven by 4543 decode and arduino wich does all the harder stuff
    3I6_bhVRSSY
    94782
    code, feel free to use and tell possible improvements!

    Code:
    /*
    remember resistors for display, if needed
    4543 uno 7-segment uln2003
    D4 11
    D3 12
    D2 11
    D1 10
    8-GND
    8 7
    9 6
    10 5
    11 4

    1-vcc
    2----------------7
    3----------------6
    4----------------5
    5----------------4
    6-gnd
    7-gnd
    8-gnd
    9------------------------------A
    10-----------------------------B
    11-----------------------------C
    12-----------------------------D
    13-----------------------------E
    14-----------------------------G
    15-----------------------------F
    16-GND
    */

    int const t =1;
    int count;


    void setup()
    {
    DDRD = DDRD | B11111100; //Data direction register D, 0=input, 1=output: pins 4-7 output
    DDRB = B00000011; // 8, 9 outputs
    }

    void loop()
    {
    PORTD = B11110000; //display 0
    PORTB = B00000001; //turn on digit 1
    picknumber(count / 1 % 10);
    delay(t);
    PORTD = B11110000; //display 0
    PORTB = B00000010; //turn on digit 2
    picknumber(count / 10 % 10);
    delay(t);
    PORTD = B11110000; //display 0
    PORTB = B00000100; //turn on digit 3
    picknumber(count / 100 % 10);
    delay(t);
    PORTD = B11110000; //display 0
    PORTB = B00001000; //turn on digit 4
    picknumber(count / 1000 % 10);
    delay(t);

    if (count > 9999) //reset after ''overflow''
    {
    count = 0;
    }
    else count++; //increment
    }




    void picknumber( int count)
    {
    switch (count)
    {
    case 0:PORTD = B00000000; break;
    case 1:PORTD=B00010000; break; //1
    case 2:PORTD=B01000000; break; //2
    case 3:PORTD=B01010000; break; //3
    case 4:PORTD=B10000000; break; //4
    case 5:PORTD=B10010000; break; //5
    case 6:PORTD=B11000000; break; //6
    case 7:PORTD=B11010000; break; //7
    case 8:PORTD=B00100000; break; //8
    case 9:PORTD=B00110000; break; //9
    }
    }


    Comments
 

EE World Online Articles

Loading

 
Top