![]() ![]() ![]() Use that as an interrupt, and every 10 interrupts do you 1/10th of a second action. The Maxim RTCs have a 1 KHz square wave output. ![]() You can simply count the main oscillator to (F_CPU / 1000ul / 100) -> that will produce an interval of 100ms. You may have to adjust the 100 variable to some value +/- to account for your specific processor crystal accuracy but I'm sure you can work that out. Well if you just want to perform a task at a fast but periodic rate use the MSTimer2 library and set it to interrupt every 100msec, and perform your task in the ISR. I'm given the time of the master clock in tenths, that's why I need that sort of precision. The result of the math operation, must match with the same operation made by a "master" device with it's own clock (and this is a proven highly accurate one). You can easily make a clock with a precision of tenths of a second but how accurate do you need it to be? If you set it to the correct time and then come back a day later, how many seconds out from the correct time is it allowed to be? If you want to change the output every ten0.1 second, does it matter of the interval is actually 0.101 second, or 0.999 second? How about 0.11 second or 0.99 second? This means that the hand will be shown rotated clockwise by the required amount.You haven't answered my question. We draw the hour hand first, using a formula that rotates the coordinate system counterclockwise by a number of degrees determined by the current hour and minute. ![]() Letting the painter handle transformations is often easier than performing manual calculations just to draw the contents of a custom widget. The painter takes care of all the transformations made during the paint event, and ensures that everything is drawn correctly. To make our code simpler, we will draw a fixed size clock face that will be positioned and scaled so that it lies in the center of the widget. We use a scale factor that let's us use x and y coordinates between -100 and 100, and that ensures that these lie within the length of the widget's shortest side. The translation moves the origin to the center of the widget, and the scale operation ensures that the following drawing operations are scaled to fit within the widget. This makes drawing of diagonal lines much smoother. We call QPainter::setRenderHint() with QPainter::Antialiasing to turn on antialiasing. Painters can be used to draw on any QPaintDevice, but they are usually used with widgets, so we pass the widget instance to the painter's constructor. The contents of custom widgets are drawn with a QPainter. It is also useful to determine the current time before we start drawing. We also determine the length of the widget's shortest side so that we can fit the clock face inside the widget. The minute hand's color has an alpha component of 191, meaning that it's 75% opaque. Since we connected the timer's timeout() signal to this slot, it will be called at least once every five seconds.īefore we set up the painter and draw the clock, we first define two lists of QPoints and two QColors that will be used for the hour and minute hands. This happens when the widget is first shown, and when it is covered then exposed, but it is also executed when the widget's update() slot is called. The paintEvent() function is called whenever the widget's contents need to be updated. Void AnalogClock ::paintEvent( QPaintEvent *) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |