Digital clock with seven segment digital display

Source: Internet
Author: User
Tags knowledge base

Summary

The vast majority of electronic products use seven-segment digital display, if the software can also simulate this effect how good? Before this article, VC Knowledge Base online magazine there have been two articles on how to achieve this effect, there is a simple implementation method, but the figure is not realistic, while another implementation of the effect, although lifelike, but must rely on bitmap resources, and can not set the foreground color and background color. After careful research and experiment, the author finally found a better solution. This article will detail seven segment digital display digital clock realization.

Key seven segment digital display digital clock

Implementation principle

We know that the display of clocks consists of time, minutes, seconds, and colons, so we can use the following functions: Drawhour,drawminute,drawsecond and Draw2dot. Since time, minutes, and seconds are made up of two digits (preceded by 10 plus 0), you can then decompose the problem and draw a single number with Drawsinglenunber. How do you draw a single number? Here is a look at the composition of the seven segment of the digital, we use 1 to 7 of the label to represent each paragraph.

Since each number is pieced together by these seven paragraphs, so we can use the switch statement in the Drawsinglenumber function, according to different numbers to draw different paragraphs, the next task is how to draw the seven paragraphs, each paragraph is a color filled with a polygon.

void Cdigitalclock::D rawsinglenumber (int nnum,int nleft)
{
Switch (nnum)
{
Case 0:
DrawSection1 (Nleft);
DrawSection2 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection5 (Nleft);
DrawSection6 (Nleft);
Break
Case 1:
DrawSection2 (Nleft);
DrawSection3 (Nleft);
Break
Case 2:
DrawSection1 (Nleft);
DrawSection2 (Nleft);
DrawSection4 (Nleft);
DrawSection5 (Nleft);
DrawSection7 (Nleft);
Break
Case 3:
DrawSection1 (Nleft);
DrawSection2 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection7 (Nleft);
Break
Case 4:
DrawSection2 (Nleft);
DrawSection3 (Nleft);
DrawSection6 (Nleft);
DrawSection7 (Nleft);
Break
Case 5:
DrawSection1 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection6 (Nleft);
DrawSection7 (Nleft);
Break
Case 6:
DrawSection1 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection5 (Nleft);
DrawSection6 (Nleft);
DrawSection7 (Nleft);
Break
Case 7:
DrawSection1 (Nleft);
DrawSection2 (Nleft);
DrawSection3 (Nleft);
Break
Case 8:
DrawSection1 (Nleft);
DrawSection2 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection5 (Nleft);
DrawSection6 (Nleft);
DrawSection7 (Nleft);
Break
Case 9:
DrawSection1 (Nleft);
DrawSection3 (Nleft);
DrawSection4 (Nleft);
DrawSection2 (Nleft);
DrawSection6 (Nleft);
DrawSection7 (Nleft);
Break
Default
;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.