Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : My Big Clock!
Author | Message | ||||
thetinkerer Regular Member Joined: 16/06/2011 Location: AustraliaPosts: 68 |
For interest sake I thought that I would post this code: It's a big clock and was/is an experiment in showing large 7 segment type display with the maximite while keeping the execution time down. While there were many different ways to tackel this, I choose to have a subroutine for each digit. This uses program space but keeps the program complexity and execution times down as the call to the fonts is carried out by one line of code (line 50). The other thing I have done is only update the digit that has changed to that we don't have to re-paint the whole clock on the screen every second. It seems to work pretty well and the code is structure so that using this in an other program is straight forward as is modifying the fonts to look prettier. Here is the code: '********************************************************
'* M Y B I G C L O C K - The Tinkerer 2011 * '******************************************************** 1 cls 3 dim DigitX 4 dim DigitY 9 dim LastTime$ 10 dim currentTime$ 20 DigitX = 10 21 DigitY = 10 22 CurrentTime$ = time$ 24 If CurrentTime$ <> lasttime$ then 'only do this if the time has changed 33 for Loop = 1 to 8 34 newchar$ = mid$(currentTime$,Loop,1) 35 oldchar$ = mid$(lastTime$,Loop,1) 36 If oldchar$ <> newchar$ then 'only redraw the character which has change 47 If asc(newchar$) > 47 then 48 If ASC(newchar$) < 58 THEN 49 NUM = ASC(newchar$)- 48 50 GOSUB 2000 + (NUM * 100) 'calcute which address to goto 58 EndIf 67 If asc(newchar$) = 58 then 69 GOSUB 3000 71 EndIf 80 EndIf 81 EndIf 82 DigitX = DigitX + 40 83 next Loop 84 EndIf 90 LastTime$ =currentTime$ 100 goto 20 450 end 1200 return 2097'********************************************* 2098' Draw 1 2099'********************************************* 2100 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2110 LINE (DigitX + 10,DigitY + 0)-(DigitX + 15, DigitY + 20),1,bf 'segment b 2120 LINE (DigitX + 10,DigitY + 25)-(DigitX + 15, DigitY + 45),1,bf 'segment C 2170 return 2197'********************************************* 2198' Draw 2 2199'********************************************* 2200 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2201 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2210 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2230 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2240 LINE (DigitX ,DigitY + 25)-(DigitX + 5, DigitY + 40),1,bf 'segment E 2260 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2270 return 2297'********************************************* 2298' Draw 3 2299'********************************************* 2300 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2301 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2302 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2303 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2304 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2305 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2306 return 2397'********************************************* 2398' Draw 4 2399'********************************************* 2400 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2401 LINE (DigitX + 20,DigitY )-(DigitX + 25, DigitY + 20),1,bf 'segment b 2402 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 45),1,bf 'segment C 2403 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2404 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2410 return 2497'********************************************* 2498' Draw 5 2499'********************************************* 2500 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2501 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2520 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2530 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2540 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2545 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2570 return 2597'********************************************* 2598' Draw 6 2599'********************************************* 2600 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2601 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2620 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2630 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2640 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2650 LINE (DigitX ,DigitY + 25)-(DigitX + 5, DigitY + 40),1,bf 'segment E 2660 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2680 return 2697'********************************************* 2698' Draw 7 2699'********************************************* 2700 LINE (DigitX ,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2701 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2702 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2703 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 45),1,bf 'segment C 2704 return 2797'********************************************* 2798' Draw 8 2799'********************************************* 2800 LINE (DigitX,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2801 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2810 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2820 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2830 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2840 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2850 LINE (DigitX ,DigitY + 25)-(DigitX + 5, DigitY + 40),1,bf 'segment E 2860 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2880 return 2897'********************************************* 2898' Draw 9 2899'********************************************* 2900 LINE (DigitX,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2901 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2910 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2920 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2940 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2945 LINE (DigitX + 5,DigitY + 20 )-(DigitX + 20, DigitY + 25),1,bf 'segment G 2980 return 1997'********************************************* 1998' Draw 0 1999'********************************************* 2000 LINE (DigitX,DigitY )-(DigitX + 30, DigitY + 50),0,bf 'blank out digit 2001 LINE (DigitX + 5,DigitY)-(DigitX + 20, DigitY + 5),1,bf 'segment A 2002 LINE (DigitX + 20,DigitY + 5)-(DigitX + 25, DigitY + 20),1,bf 'segment b 2003 LINE (DigitX + 20,DigitY + 25)-(DigitX + 25, DigitY + 40),1,bf 'segment C 2004 LINE (DigitX + 5,DigitY + 40 )-(DigitX + 20, DigitY + 45),1,bf 'segment D 2005 LINE (DigitX,DigitY + 5)-(DigitX + 5, DigitY + 20),1,bf 'segment F 2006 LINE (DigitX ,DigitY + 25)-(DigitX + 5, DigitY + 40),1,bf 'segment E 2007 return 2997'********************************************* 2998' Draw the Colon 2999'********************************************* 3000 LINE (DigitX + 5,DigitY + 5)-(DigitX + 15, DigitY + 20),1,bf 'segment b 3002 LINE (DigitX + 5,DigitY + 30)-(DigitX + 15, DigitY + 45),1,bf 'segment C 3006 return |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
Yep, works fine. Yeah thats a good idea. I had the same problem on a program I'm working on, a wind/solar controller. It displays the battery volts, amps and watts in big numbers, I used a block fill "BF" to clear each number before drawing the new number. To reduce the flicker, I first check if the displayed number is the same as the new number before block filling and drawing the new number. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
thetinkerer Regular Member Joined: 16/06/2011 Location: AustraliaPosts: 68 |
I carried out a trial with a modified version of this program which wrote 6 clocks down the page to see if there was any visible delay. With writing the 6 clocks to the screen, it still performed well. I think that as long as we don't do too many calls to lines,rectangles or circles to create large fonts and keep things efficient, we should be ok. I was looking at the Maximite soruce code today and was thinking that it should be fairly straight forawrd to have a font mutiplier. 1 - normal size 2 - double the size 3 - three times the size ... etc The fonts would get chunky as the size of the pixels will go from 1 to 2 x2 to 3x3 etc. but that would be Ok. This could be handy for the type of project that you are doing. .. and some of the things I have in mind too. Marc |
||||
Print this page |