'=========================================================================== ' Subject: LED SCREEN SAVER Date: 08-12-96 (21:02) ' Author: Jonathan Leger Code: QB, QBasic, PDS ' Origin: leger@mail.dtx.net Packet: GRAPHICS.ABC '=========================================================================== DEFINT A-Z 'LedDisplay() routine Original Author: Scott Pessoni - August 1995 '---> Modified by Jonathan Leger <--- 'All other code, including InitLedDisplay() and InitLedBar(), written 'by Jonathan Leger (leger@mail.dtx.net). DECLARE SUB InitLedDisplay (x%, y%, onc%, offc%, digits%, v%, a%) DECLARE SUB InitLedBar (x%, y%, onc%, offc%, elems%, maxval%, v%, a%) DECLARE SUB LedBar (Number#) DECLARE SUB LedDisplay (Number#) DIM SHARED DisplayLedX, DisplayLedY, LedDigits, OnColor, OffColor, apage, vpage DIM SHARED GraphLedX, GraphLedY, GraphElements, GraphNum 'This string, scrollmsg$, _must_ have a space at the end. scrollmsg$ = "REAL PROGRAMERS USE BASIC... ": scrollclr = 14 SCREEN 7 t# = TIMER x# = 0 DO x# = x# + 1 LOOP UNTIL TIMER - t# > 1 x# = x# / 5 RANDOMIZE TIMER cx = INT(RND * 280): cy = INT(RND * 160) + 12 xd = INT(RND * 2) + 1 IF xd = 1 THEN xdir = -1 ELSE xdir = 1 END IF yd = INT(RND * 2) + 1 IF yd = 1 THEN ydir = -1 ELSE ydir = 1 END IF digits = 1: fore = 9: back = 8 sloc = 40: slet = 1: stog = 0 DO FOR Count# = VAL(STRING$(digits - 1, "9")) TO VAL(STRING$(digits, "9")) x2# = 0 DO x2# = x2# + 1 LOOP UNTIL x2# >= x# stog = stog + 1 IF stog = 5 THEN stog = 0 SCREEN , , apage, vpage LOCATE 1, 1: PRINT STRING$(40, " "); IF fore = 15 THEN COLOR 9 ELSE COLOR fore + 1 END IF LOCATE 1, sloc PRINT MID$(scrollmsg$, slet, (40 - sloc)); sloc = sloc - 1 IF sloc = 0 THEN sloc = 1 slet = slet + 1 FOR sc = 2 TO 25 IF slet - sc < 1 THEN EXIT FOR LOCATE sc, 1: PRINT MID$(scrollmsg$, slet - sc, 1); NEXT sc IF sc = 26 AND slet - sc = LEN(scrollmsg$) THEN slet = 1: sloc = 40 END IF END IF END IF InitLedDisplay cx, cy, 0, 0, digits, 0, 1 LedDisplay -1 cx = cx - xdir cy = cy - ydir IF cx < 12 THEN xdir = xdir * -1 cx = 12 ELSEIF cy < 12 THEN ydir = ydir * -1 cy = 12 ELSEIF cx > 280 THEN xdir = xdir * -1 cx = 280 ELSEIF cy > 180 THEN ydir = ydir * -1 cy = 180 END IF InitLedDisplay cx, cy, fore, back, digits, 0, 1 LedDisplay Count# key$ = INKEY$ SELECT CASE key$ CASE CHR$(27) EXIT DO END SELECT IF (Count# MOD 100) = 0 THEN fore = fore + 1 IF fore > 15 THEN fore = 9 END IF NEXT Count# digits = digits + 1 LOOP SUB InitLedBar (x%, y%, onc%, offc%, elems%, maxval%, v%, a%) apage% = a%: vpage% = v% SCREEN , , apage%, vpage% GraphLedX = x% '|- Upper Left corner of GraphLedY = y% '| Led Graph display GraphElements = elems% 'Number of graph elements. Maximum 32 GraphNum = maxval% 'The number when the graph is 100% END SUB SUB InitLedDisplay (x, y, onc, offc, digits, v, a) apage = a: vpage = v SCREEN , , apage, vpage DisplayLedX = x '|- Upper Left corner of DisplayLedY = y '| Led Digit display LedDigits = digits 'Number of digits to have on display OnColor = onc: OffColor = offc LedDisplay -1 END SUB 'LedBar: A simulated Led Bargraph '----------------------------------------------- 'LedBar Number ' Number = The current number you want to update the bar graph with '----------------------------------------------- SUB LedBar (Number#) IF Number# < 0 THEN 'If Negitive then blank Bar Graph FOR MakeGraph = 1 TO GraphElements * 2 STEP 2 'Make the Bar graph LINE (GraphLedX + MakeGraph, GraphLedY)-(GraphLedX + MakeGraph, GraphLedY + 5), OffColor% NEXT MakeGraph EXIT SUB END IF Elements = INT(Number# * GraphElements / GraphNum) 'Calculate Number Elements IF Elements > GraphElements THEN Elements = GraphElements 'Check limts '----------------- Draw Bar Graph -------------------------------- FOR MakeGraph = 1 TO Elements * 2 STEP 2 'Make the Bar graph (Lit) LINE (GraphLedX + MakeGraph, GraphLedY)-(GraphLedX + MakeGraph, GraphLedY + 5), OnColor% NEXT MakeGraph FOR MakeGraph = Elements * 2 + 1 TO GraphElements * 2 STEP 2 'Make the Bar graph (Dim LINE (GraphLedX + MakeGraph, GraphLedY)-(GraphLedX + MakeGraph, GraphLedY + 5), OffColor% NEXT MakeGraph '------------------------------------------------------------------ END SUB 'LedDisplay: Generates a simulated Digital Led Display. '------------------------------------------------------------ 'LedDisplay (Number) ' Number = The number you want to display on the Digital Display '------------------------------------------------------------ SUB LedDisplay (Number#) SCREEN , , apage, vpage IF Number# < 0 THEN 'Setup Led Display panel FOR PlotX = DisplayLedX TO DisplayLedX + ((LedDigits - 1) * 8) STEP 8 '----------- One LED Matrix digit -------------------- LINE (PlotX + 1, DisplayLedY)-(PlotX + 5, DisplayLedY), OffColor% LINE (PlotX, DisplayLedY + 1)-(PlotX, DisplayLedY + 5), OffColor% LINE (PlotX + 6, DisplayLedY + 1)-(PlotX + 6, DisplayLedY + 5), OffColor% LINE (PlotX + 1, DisplayLedY + 6)-(PlotX + 5, DisplayLedY + 6), OffColor% LINE (PlotX, DisplayLedY + 7)-(PlotX, DisplayLedY + 11), OffColor% LINE (PlotX + 6, DisplayLedY + 7)-(PlotX + 6, DisplayLedY + 11), OffColor% LINE (PlotX + 1, DisplayLedY + 12)-(PlotX + 5, DisplayLedY + 12), OffColor% '------------------------------------------------------ NEXT PlotX EXIT SUB END IF Number# = FIX(Number#) 'Get rid of the decimals incase there are some Number# = VAL(LEFT$(STR$(Number#), LedDigits + 1)) 'Chop Number to LED size PlotX = DisplayLedX IF LEN(STR$(Number#)) - 1 < LedDigits THEN 'Clear Unused digits FOR ClearEmptyDigits = 1 TO LedDigits - (LEN(STR$(Number#)) - 1) LINE (PlotX + 1, DisplayLedY)-(PlotX + 5, DisplayLedY), OffColor% LINE (PlotX, DisplayLedY + 1)-(PlotX, DisplayLedY + 5), OffColor% LINE (PlotX + 6, DisplayLedY + 1)-(PlotX + 6, DisplayLedY + 5), OffColor% LINE (PlotX + 1, DisplayLedY + 6)-(PlotX + 5, DisplayLedY + 6), OffColor% LINE (PlotX, DisplayLedY + 7)-(PlotX, DisplayLedY + 11), OffColor% LINE (PlotX + 6, DisplayLedY + 7)-(PlotX + 6, DisplayLedY + 11), OffColor% LINE (PlotX + 1, DisplayLedY + 12)-(PlotX + 5, DisplayLedY + 12), OffColor% PlotX = PlotX + 8 NEXT ClearEmptyDigits END IF FOR PlotDigit = 1 TO LEN(STR$(Number#)) - 1 'Plot each number to a LED WorkDigit$ = MID$(STR$(Number#), PlotDigit + 1, 1) 'Get 1 Digit SELECT CASE WorkDigit$ 'Find and select which elements to turn on CASE "0" E1 = OnColor%: E2 = OnColor%: E3 = OnColor%: E4 = OffColor%: E5 = OnColor%: E6 = OnColor%: E7 = OnColor% CASE "1" E1 = OffColor%: E2 = OffColor%: E3 = OnColor%: E4 = OffColor%: E5 = OffColor%: E6 = OffColor%: E7 = OnColor% CASE "2" E1 = OffColor%: E2 = OnColor%: E3 = OnColor%: E4 = OnColor%: E5 = OnColor%: E6 = OnColor%: E7 = OffColor% CASE "3" E1 = OffColor%: E2 = OnColor%: E3 = OnColor%: E4 = OnColor%: E5 = OffColor%: E6 = OnColor%: E7 = OnColor% CASE "4" E1 = OnColor%: E2 = OffColor%: E3 = OnColor%: E4 = OnColor%: E5 = OffColor%: E6 = OffColor%: E7 = OnColor% CASE "5" E1 = OnColor%: E2 = OnColor%: E3 = OffColor%: E4 = OnColor%: E5 = OffColor%: E6 = OnColor%: E7 = OnColor% CASE "6" E1 = OnColor%: E2 = OffColor%: E3 = OffColor%: E4 = OnColor%: E5 = OnColor%: E6 = OnColor%: E7 = OnColor% CASE "7" E1 = OffColor%: E2 = OnColor%: E3 = OnColor%: E4 = OffColor%: E5 = OffColor%: E6 = OffColor%: E7 = OnColor% CASE "8" E1 = OnColor%: E2 = OnColor%: E3 = OnColor%: E4 = OnColor%: E5 = OnColor%: E6 = OnColor%: E7 = OnColor% CASE "9" E1 = OnColor%: E2 = OnColor%: E3 = OnColor%: E4 = OnColor%: E5 = OffColor%: E6 = OffColor%: E7 = OnColor% END SELECT 'Plot the LEDs to the screen------------------------ LINE (PlotX, DisplayLedY + 1)-(PlotX, DisplayLedY + 5), E1 LINE (PlotX + 1, DisplayLedY)-(PlotX + 5, DisplayLedY), E2 LINE (PlotX + 6, DisplayLedY + 1)-(PlotX + 6, DisplayLedY + 5), E3 LINE (PlotX + 1, DisplayLedY + 6)-(PlotX + 5, DisplayLedY + 6), E4 LINE (PlotX, DisplayLedY + 7)-(PlotX, DisplayLedY + 11), E5 LINE (PlotX + 1, DisplayLedY + 12)-(PlotX + 5, DisplayLedY + 12), E6 LINE (PlotX + 6, DisplayLedY + 7)-(PlotX + 6, DisplayLedY + 11), E7 '-------------------------------------------------- PlotX = PlotX + 8 NEXT PlotDigit PCOPY apage, vpage SCREEN , , vpage, vpage END SUB