'=========================================================================== ' Subject: PB SCALABLE 7-SEGMENT DISPLAY Date: 11-10-98 (12:32) ' Author: Dieter Folger Code: PB ' Origin: folger@bamberg.baynet.de Packet: GRAPHICS.ABC '=========================================================================== '---------------------------------' ' 7SEGMENT.BAS for Power Basic ' ' Scalable 7-segment display ' ' VGA card required ' ' Freeware (c) Dieter Folger 1998 ' '---------------------------------' SCREEN 12 'VGA 640x480x16 DEFINT A-Z '======================================================== 'Demo program: x = 20: y = 100 'coordinates of upper left corner fg = 11: bg = 0 'colors fore- and background Number$ = "12.34567890" 'example to show FOR s = 1 TO 50 'size 1 to 50 CLS : LOCATE 5, 5 PRINT "Display size"; s ;"(Press a key)" Display Number$, x, y, fg, bg, s 'call routine to show DO : K$ = INKEY$ : LOOP UNTIL LEN(K$) 'wait for a key IF K$ = CHR$(27) THEN EXIT FOR NEXT END '======================================================== SUB Display (Number$, x, y, fg, bg, s) ' Number$ = Number to display; ' x,y = coordinates of upper left display position; ' fg, bg = foreground & background colors; ' s = size of display '-------------------------------------------------------- SHARED z RESTORE ' bitmap data FOR i = 0 TO 9: READ value(i): NEXT FOR j = 1 TO LEN(Number$) IF MID$(Number$, j, 1) = "." THEN ' if decimal point CIRCLE (x + dist - s / 2, y + 3 + 2 * s), s / 8, fg PAINT (x + dist - s / 2, y + 3 + 2 * s), fg, fg INCR j END IF z = Value(VAL(MID$(Number$, j, 1))) Segment 0, x + dist, y + 2 + s, 0 ' 1 = middle Segment 1, x + dist, y, 1 ' 2 = upper left Äð7ÄÄ Segment 1, x + dist, y + 2 + s, 2 ' 3 = down left 2 ³ ³ 6 Segment 0, x + dist, y + 4 + 2 * s, 3 ' 4 = bottom ÄÄ1ÄÄ Segment 1, x + dist + 2 + s, y + 2 + s, 4 ' 5 = down right 3 ³ ³ 5 Segment 1, x + dist + 2 + s, y, 5 ' 6 = upper right ÄÄ4ÄÄ Segment 0, x + dist, y, 6 ' 7 = top INCR dist, s * 2 + 3 ' increase distance between digits NEXT DATA 126,48,109,121,51,91,95,112,127,123 ' bitmaps for digits 0 - 9 '-------------------------------------------- 'construction of bitmaps: '-------------------------------------------- 'digit 0 is bitmap 126 (=binary 01111110) 'all segments are shown ³³³³³³³ '(=1) except middle (=0) segment 7654321 ' ³³³³³³³ 'digit 3 is bitmap 212 (=binary 01111001) 'shown are segments 1, 4, 5, 6 and 7 '-------------------------------------------- END SUB '------------------------------------------- SUB Segment (p, x, y, b) 'routine paints one segment (across or down) '------------------------------------------- SHARED s, fg, bg, z cl = bg: IF BIT(z, b) THEN cl = fg FOR i = 0 TO s \ 8 IF p THEN ' Segment down (p=1) LINE (x + i, y + i) - (x + i, y + s - i), cl LINE (x - i, y + i) - (x - i, y + s - i), cl ELSE ' Segment across (p=0) LINE (x + 1 + i, y - 1 - i) - (x + 1 + s - i, y - 1 - i), cl LINE (x + 1 + i, y - 1 + i) - (x + 1 + s - i, y - 1 + i), cl END IF NEXT END SUB