DECLARE SUB diagram () DECLARE SUB gridbox (rpot AS LONG) DECLARE SUB plot (rpot AS LONG, rfixed AS LONG) DECLARE SUB ploterase (upto AS INTEGER, rpot AS LONG, rfixed AS LONG) DEFINT A-Z SCREEN 12 WIDTH 80, 60 CLS 'p coords are real BASIC coords with y=0 at top 'g coords are logical with y=0 at bottom (converted to p at last step) ' therefore... py = F of (gy) = pymax - gy CONST false = 0 CONST true = NOT false CONST pxmax = 640 CONST pymax = 480 CONST xbox = 40 CONST ybox = 40 CONST gtop = pymax - 3 'gtop = 477 CONST gbottom = gtop - ybox * 10 'gbottom = 77 CONST gleft = 40 CONST gright = gleft + xbox * 10 'gright = 440 CONST gxrange = gright - gleft + 1 'gxrange = 401 CONST gyrange = gtop - gbottom + 1 'gyrange = 401 CONST scalecolor = 10 CONST schemcolor = 5 CONST IDEALlogcolor = 11 CONST IDEALoutimpcolor = 9 CONST SIMvdivcolor = 14 CONST SIMinimpcolor = 12 CONST SIMoutimpcolor = 13 'initial values rfixed& = 10 rpot& = 100 diagram LOCATE 55, 6: COLOR 15: PRINT "IDEAL LOG POT"; LOCATE 56, 6: COLOR IDEALlogcolor: PRINT "Log function"; LOCATE 58, 6: COLOR IDEALoutimpcolor: PRINT "output resistance"; LOCATE 55, 36: COLOR 15: PRINT "SIMULATED LOG POT"; LOCATE 56, 36: COLOR SIMvdivcolor: PRINT "Voltage divider ratio"; LOCATE 57, 36: COLOR SIMinimpcolor: PRINT "Input resistance"; LOCATE 58, 36: COLOR SIMoutimpcolor: PRINT "output resistance"; LOCATE 53, 20: COLOR scalecolor: PRINT "Percent of CW rotation"; DO key$ = INKEY$ LOOP UNTIL key$ = "" 'clear keyboard buffer DO 'label diagram LOCATE 24, 63: COLOR 15: PRINT USING "####"; rpot& LOCATE 29, 73: COLOR 15: PRINT rfixed& 'plot graph gridbox rpot& plot rpot&, rfixed& 'save parameter values just used, before user changes them OLDrfixed& = rfixed& OLDrpot& = rpot& DO 'wait for key DO WHILE key$ = "" key$ = INKEY$ LOOP 'user changes r values: 'resistor values need only 3 digits 'let them vary from 1 to 1000 SELECT CASE key$ 'UP CASE CHR$(0) + "H" IF rfixed& < 100 THEN rfixed& = rfixed& + 1 ELSE rfixed& = rfixed& + 10 IF rfixed& > 1000 THEN rfixed& = 1000 'DOWN CASE CHR$(0) + "P" IF rfixed& <= 100 THEN rfixed& = rfixed& - 1 ELSE rfixed& = rfixed& - 10 IF rfixed& < 1 THEN rfixed& = 1 'RIGHT CASE CHR$(0) + "M" IF rpot& < 100 THEN rpot& = rpot& + 1 ELSE rpot& = rpot& + 10 IF rpot& > 1000 THEN rpot& = 1000 'LEFT CASE CHR$(0) + "K" IF rpot& <= 100 THEN rpot& = rpot& - 1 ELSE rpot& = rpot& - 10 IF rpot& < 1 THEN rpot& = 1 'ESCAPE CASE CHR$(27) END END SELECT 'discard key and check for another before re-plotting key$ = INKEY$ LOOP UNTIL key$ = "" 'if key was pressed while plotting, plot sub erased it already 'or else key was pressed after plot was complete, then erase it now IF complete THEN ploterase gright, OLDrpot&, OLDrfixed& LOOP SUB diagram 'schematic origin point in center of bottom-left junction dot sx = pxmax - 102 sy = 258 'pot resistor LINE (sx, sy)-STEP(0, -45), schemcolor 'up from baseline to resistor bottom LINE -STEP(5, -3), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-5, -3), schemcolor LINE -STEP(0, -15), schemcolor 'up from resistor top LINE -STEP(-20, 0), schemcolor 'turn left 'pot wiper LINE (sx + 10, sy - 69)-STEP(-5, -3), schemcolor 'arrow bottom up \ to point LINE -STEP(5, -3), schemcolor 'arrow point up / to top LINE STEP(-5, 3)-STEP(55, 0), schemcolor 'arrow shaft 'dot bottom left LINE (sx - 2, sy + 2)-STEP(4, -4), schemcolor, BF 'dot bottom right LINE (sx + 33, sy + 2)-STEP(4, -4), schemcolor, BF 'fixed resistor LINE (sx - 20, sy)-STEP(80, 0), schemcolor 'baseline LINE STEP(-25, 0)-STEP(0, -15), schemcolor 'back to left a little then up LINE -STEP(-5, -3), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(10, -6), schemcolor LINE -STEP(-10, -6), schemcolor LINE -STEP(5, -3), schemcolor LINE -STEP(0, -15), schemcolor 'up from resistor top 'dot top LINE STEP(-2, 2)-STEP(4, -4), schemcolor, BF LOCATE 15, 64: COLOR 15: PRINT "Press "; CHR$(27); CHR$(26); LOCATE 16, 64: COLOR 15: PRINT "to vary pot"; LOCATE 36, 70: COLOR 15: PRINT "Press "; CHR$(24); CHR$(25); LOCATE 37, 71: COLOR 15: PRINT "to vary"; LOCATE 38, 71: COLOR 15: PRINT "fixed R"; END SUB SUB gridbox (rpot AS LONG) 'horizontal lines FOR hl = 0 TO 10 gy = gbottom + hl * 40 py = pymax - gy px1 = gleft px2 = gright LINE (px1, py)-(px2, py), scalecolor LOCATE 51 - hl * (ybox \ 8), 1 COLOR SIMinimpcolor rmark! = rpot& * hl / 10 IF rmark! >= 100 THEN PRINT USING "####"; rmark!; ELSE PRINT USING "##.#"; rmark!; LOCATE 51 - hl * (ybox \ 8), 56 COLOR SIMvdivcolor PRINT STR$(hl * 10); "%"; NEXT 'vertical lines FOR vl = 0 TO 10 gx = gleft + vl * xbox px = gx py1 = pymax - gbottom py2 = pymax - gtop LINE (px, py1)-(px, py2), scalecolor LOCATE 52, 4 + vl * xbox \ 8 COLOR scalecolor PRINT USING "###"; vl * 10; PRINT "%"; NEXT 'grid dots FOR gy = gbottom TO gtop STEP ybox \ 5 FOR gx = gleft TO gright STEP xbox \ 5 px = gx py = pymax - gy PSET (px, py), scalecolor NEXT NEXT END SUB SUB plot (rpot AS LONG, rfixed AS LONG) SHARED key$, complete complete = true '*** plot resistor functions *** 'gx derived by moving right, counting by 1 pixel at a time 'x quantity derived from gx 'y quantity derived from f(x) 'gy derived from y FOR gx = gleft TO gright 'if a key was pressed, then erase what was done so far key$ = INKEY$ IF key$ <> "" THEN ploterase gx - 1, rpot, rfixed complete = false EXIT FOR END IF px = gx 'scale x from 0 to 1 x! = (gx - gleft) / gxrange 'IDEAL LOG POT 'parallel resistor calcs rleft! = rpot& * 10 ^ (x! * 2) / 100 rright! = rpot& - rleft! 'PLOT ACTUAL LOG FUNCTION 'scale y from 0 to 100 y! = 10 ^ (x! * 2) gy = y! * gyrange / 100 + gbottom py = pymax - gy PSET (px, py), IDEALlogcolor 'PLOT RESISTANCE SEEN BY LOAD 'scale y from 0 to 1 * rpot& y! = ((rleft! * rright!) / (rleft! + rright!)) / rpot& gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), IDEALoutimpcolor 'SIMULATED LOG POT 'parallel resistor calcs rleft! = rpot& * x! rright! = rpot& - rleft! rparaleft! = (rfixed& * rleft!) / (rfixed& + rleft!) 'PLOT EQUIV POT RESISTANCE RATIO (VOLTAGE DIVIDER) 'scale y from 0 to 1 * rpot& y! = rparaleft! / (rparaleft! + rright!) gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), SIMvdivcolor 'PLOT RESISTANCE SEEN BY SOURCE 'scale y from 0 to 1 * rpot& y! = (rparaleft! + rright!) / rpot& gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), SIMinimpcolor 'PLOT RESISTANCE SEEN BY LOAD 'scale y from 0 to 1 * rpot& y! = ((rparaleft! * rright!) / (rparaleft! + rright!)) / rpot& gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), SIMoutimpcolor NEXT END SUB SUB ploterase (upto AS INTEGER, rpot AS LONG, rfixed AS LONG) '*** erase all plots (except ideal log) after r changes *** 'plot parallel resistor function IN BLACK 'code copied from plot except colors are set to black FOR gx = gleft TO upto px = gx x! = (gx - gleft) / gxrange rleft! = rpot& * x! rright! = rpot& - rleft! rparaleft! = (rfixed& * rleft!) / (rfixed& + rleft!) 'ERASE EQUIV POT RESISTANCE RATIO (VOLTAGE DIVIDER) y! = rparaleft! / (rparaleft! + rright!) gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), 0 'ERASE RESISTANCE SEEN BY SOURCE y! = (rparaleft! + rright!) / rpot& gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), 0 'ERASE RESISTANCE SEEN BY LOAD y! = ((rparaleft! * rright!) / (rparaleft! + rright!)) / rpot& gy = y! * gyrange + gbottom py = pymax - gy PSET (px, py), 0 NEXT END SUB