# Need help for programming a digital clock

Hello there

This is my 1st post in this forum.I am trying to make a digital clock by Turbo C. Can anyone suggest me how to start.

## Comments

• [color=Blue]Begin by entering graphics mode in Turbo C - read about initgraph() function.

The digits are formed by two types of figures: vertical segment and horizontal segment. So, to draw these types of segments create two functions: DrawHSeg (int x, int y); and DrawVSeg (int x, int y); The coordinates are needed because you need to draw the segments on different screen locations to create a full figure.

Next start calling these functions with some X,Y and figure out which segment goes where on the screen. Once you get the segment location for a full XX:XX picture on screen (each X should cover for 7 segments: 4 vertical and 3 horizontal) - remember these X,Y in an arrays of integer values:
[/color]
[code]
int XSeg [] =
{
// put your X coordinates here
};

int YSeg [] =
{
// put your Y coordinates here
};
[/code]
[color=Blue]Also, make sure that you map each segment logical index to the coordinates. You have to know for example that XSeg[5], YSeg[5] is a coordinates for some segment in first X inside "XX:XX".

After that all you need to do is draw segments according to the digits. For example if there is a digit 5 on the second place, like so: "X5:XX". This means you need to erase and draw segments according to your map of coordinates. "5" has all three horizontal segments painted, but only has two verticals: one on the left up side and one of the right down side.

It is better maybe to make a state machine, where you would not draw whole pictrure, but only hide some segments and draw some other segments. This way you avoid flickering and it would run faster.

Come to think of it - it is not that easy to make a digital clock. Use C++ for the task. Each digit is C++ object. Once the segments for a digit are painted - you remember in the C++ object which segments are drawn, so if you draw the next digit - you can skip the segments which are already painted and/or erase ones which are not needed for the digit.[/color]
Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!