/* Practice using E12 color codes for resistors */ /* (C) 1997, 1999, Rob van der Woude */ /* Latest revision 1999/02/28 */ /* Use this program at your own risk. */ /* You may copy, distribute or even modify this */ /* program, provided you leave a note explaining */ /* your modifications in this header. */ /* Initialize RexxUtil */ call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs" call SysLoadFuncs /* Change code page to enable display of Omega character */ address CMD "@CHCP 437" /* Parse command line parameter, if any */ parse upper arg level and_the_rest /* Constants */ freq = 220 Esc = "1B"X /* Colors for first and second ring */ sblack = Esc||"[0;1;37;40m" sbrown = Esc||"[0;1;37;43m" sred = Esc||"[0;1;37;41m" sorange = Esc||"[0;1;33;41m" syellow = Esc||"[0;5;30;43m" sgreen = Esc||"[0;1;37;42m" sblue = Esc||"[0;1;37;44m" smagenta = Esc||"[0;1;37;45m" sgrey = Esc||"[0;1;5;37;40m" swhite = Esc||"[0;5;30;47m" saqua = Esc||"[0;46m" /* Colors for third ring (multiplier) */ rsilver = -2 rgold = -1 rblack = 0 rbrown = 1 rred = 2 rorange = 3 ryellow = 4 rgreen = 5 rblue = 6 rmagenta = 7 rgrey = 8 rwhite = 9 /* Color display */ color. = "" color.0 = 19 color.10 = sblack||" " color.11 = sbrown||" " color.12 = sred||" " color.13 = sorange||"±±" color.14 = syellow||" " color.15 = sgreen||" " color.16 = sblue||" " color.17 = smagenta||" " color.18 = sgrey||" " color.19 = swhite||" " /* E12 range */ E12. = "" E12.0 = 12 E12.1 = 10 E12.2 = 12 E12.3 = 15 E12.4 = 18 E12.5 = 22 E12.6 = 27 E12.7 = 33 E12.8 = 39 E12.9 = 47 E12.10 = 56 E12.11 = 68 E12.12 = 82 /* Header text and position coding */ text1 = sblack||" black "||sbrown||" brown "||sred||" red "||sorange||"±orange±"||syellow||" yellow "||sgreen||" green "||sblue||" blue "||smagenta||" magenta"||sgrey||" grey "||swhite||" white "||Esc||"[0m" text2 = sblack||" 0 "||sbrown||" 1 "||sred||" 2 "||sorange||"±±±±3±±±"||syellow||" 4 "||sgreen||" 5 "||sblue||" 6 "||smagenta||" 7 "||sgrey||" 8 "||swhite||" 9 "||Esc||"[0m" text3 = sblack||" "||sbrown||" "||sred||" "||sorange||"±±±±±±±±"||syellow||" "||sgreen||" "||sblue||" "||smagenta||" "||sgrey||" "||swhite||" "||Esc||"[0m" pos1 = Esc||"[2J" pos2 = Esc||"[2;1H" pos3 = Esc||"[3;1H" pos4 = Esc||"[4;1H" pos5 = Esc||"[5;1H" pos6 = Esc||"[6;1H" pos7 = Esc||"[7;1H" pos8 = Esc||"[8;1H" pos9 = Esc||"[9;1H" pos10 = Esc||"[10;1H" pos11 = Esc||"[11;1H" pos12 = Esc||"[12;1H" pos13 = Esc||"[13;1H" pos14 = Esc||"[14;1H" pos15 = Esc||"[15;1H" pos16 = Esc||"[16;1H" pos17 = Esc||"[17;1H" pos18 = Esc||"[18;1H" /* Display help if needed */ if level = "/?" then do call Syntax end /* Display header */ do forever select when level = "2" then do line1 = pos1||Esc||"[K" line2 = pos2||Esc||"[K" line3 = pos3||Esc||"[K" leave end when level = "1" then do line1 = pos1||text3 line2 = pos2||text1 line3 = pos3||text3 leave end when level = "0" then do line1 = pos1||text1 line2 = pos2||text3 line3 = pos3||text2 leave end otherwise do call Syntax end end end say line1 say line2 say line3 /* Run main program */ do forever call Run end exit /* Main program */ Run: /* Choose random restor value */ w = random( 1, 12 ) x = random( 0, 6 ) R = E12.w * ( 10 ** x ) /* Convert value to color codes */ ring1 = E12.w % 10 ring2 = E12.w // 10 ring3 = x color1 = 10 + ring1 color2 = 10 + ring2 color3 = 10 + ring3 color1 = color.color1 color2 = color.color2 color3 = color.color3 /* Display converted color code */ say Esc||"[0;1;30m"||Esc||"[15;20HÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ" say Esc||"[14;29H"||saqua||" "||color1||saqua||" "||color2||saqua||" "||color3||saqua||" " say Esc||"[15;29H"||saqua||" "||color1||saqua||" "||color2||saqua||" "||color3||saqua||" " say Esc||"[16;29H"||saqua||" "||color1||saqua||" "||color2||saqua||" "||color3||saqua||" "||Esc||"[0m" /* Prefix Omega character with k or M if needed */ select when R > 999 & R < 1000000 then do R = R / 1000 Ohm = "k"||"EA"X end when R > 999999 then do R = R / 1000000 Ohm = "M"||"EA"X end otherwise Ohm = "EA"X end /* Ask for input */ say Esc||"[20;32HR = .... "||"EA"X call SysCurPos 19, 35 pull R2 say Esc||"[20;32HR = "||R||" "||Ohm||Esc||"[K" say Esc||"[22;1HPress any key to continue, Esc to quit" /* Quit if Esc was pressed */ if SysGetKey( "NOECHO" ) = "1B"X then do say Esc||"[22;1H"||Esc||"[K" exit end say Esc||"[22;1H"||Esc||"[K" return Syntax: /* Show help and start program in interactive mode */ do forever say pos1||pos2||" Resistor, version 1.10" say pos3||" (C) 1997, 1999, Rob van der Woude" say pos5||" Practice using E12 range of resistor color codes" say pos7||" Usage: RESISTOR " say pos8||" where can be 0 (easy)," say pos9||" 1 (medium) or 2 (highest level)" say pos11||" Do you want to start the program now?" answer = translate( SysGetKey( ) ) if answer = "N" then exit if answer = "Y" then do say pos12||Esc||"[K"||pos13||" What level?" say pos14||" Choose 0 for easyest level, or" say pos15||" choose 1 for medium level, or" say pos16||" choose 2 for the highest level." do forever say pos17 level = SysGetKey( ) if level = "0" then leave if level = "1" then leave if level = "2" then leave call beep freq, 250 freq = freq * 2 if freq > 3500 then freq = 220 end leave end if answer = "J" then leave call beep freq, 250 freq = freq * 2 if freq > 3500 then freq = 220 end return