You are here: RailNet Page 1 Home > Computer-Controlled DCC S-Gauge > Text Version 2 (Enhanced Program)
version$ = "RNLOC24d.BAS, 07-18-01"
' ver 24d: add code to ring bell automatically
' ver 24c: change code so functions work with any loco number
' ver 24b: hardcode functions 0,1,2;Move quitting message from line 11 to line 5
' ver 24a: Clean up to insert function commands
' ver 23j: Remove version comments
'============================================================================
'Sensors & Printer: Sharing same 25 pin parallel port
'NCE & Mouse: Using 9 pin RS232 Serial ports (Com ports) (Mouse #1, NCE #2)
'Initialize
SpdCirTop = 5: TimeCirCruise = 5: TimeCirStop = 4'Circle settings
SpdPtTop = 5: TimePtStop = 4: TimePtCruise = 3
CLS : LOCATE 2, 1 'Point to Point settings
PRINT "Turn 486's num lock key OFF, then press RETURN "; : INPUT X$
GetPort: LOCATE 3, 1: PRINT "Return for Com1 (Laptop) or 2 for Com2 (Tower)"; : INPUT In$
IF In$ = "2" THEN 'Tower-uses com port #2 (9 pin, mouse/NCE)
OPEN "COM2:9600,N,8,1,BIN,RS,DS0,CD0,CS0" FOR RANDOM AS #2
LOCATE 3, 1: PRINT "Opened Com2(Tower) "; SPC(40); 'None of above = run manual
ELSEIF In$ = "" THEN 'Laptop-uses com port #1
OPEN "COM1:9600,N,8,1,BIN,RS,DS0,CD0,CS0" FOR RANDOM AS #2
LOCATE 3, 1: PRINT "Opened Com1(Laptop) "; SPC(40); 'None of above = run manual
ELSE 'None of above = run manual
CLS : LOCATE 4, 1: PRINT "ERROR- '"; In$; "'is invalid Com Port #"; : GOTO GetPort
END IF
port = &H379 'Assign PORT to printer port input byte ?inp(port)&128
KEY 18, CHR$(0) + CHR$(45) 'key 18 = 'x' key (scan code 45,pg 340)
'per pg 236: 45=scan code for x key;
GOSUB GetLocoNum 'Space bar=get loco number
'============================================================================
Exec: 'Executive Program
'======8=====================================================================
LOCATE 1, 3: PRINT "AUTOMATIC TRAIN CONTROL PROGRAM (By Fred Cupp) ("; version$
LOCATE 11, 1
PRINT "11 b=bell, h=horn, l=lights, o=all off"
PRINT "12 |--------------------------------------------------------|"
PRINT " | MENU (EXECUTIVE) 'q' to quit program |"
PRINT " | Space Bar to enter new loco # (t = sensor test) |"
PRINT " | Arrows: Up/Down = Speed Up/Down, -> & <- = forward/rev |"
PRINT " | p = Pnt To Pnt Automatic | c = Circle Mode |"
PRINT " | s = Chg Pnt To Pnt Settings | d = Chg Circle Settings |"
PRINT " | \--start Pnt to Pnt w/train blocking a sensor |"
PRINT "19 |----------------------------|---------------------------|"
''PRINT "20 (NCE Subroutine writes following lines) "; version$
DO UNTIL Key$ = "q" 'q to exit
LOCATE 20, 54: PRINT "{ Key$=|" + Key$ + "|}.."
IF Key$ = " " THEN
GOSUB GetLocoNum 'Space bar=get loco number
ELSEIF Key$ = "b" THEN GOSUB NceFunctions 'bell & light on
ELSEIF Key$ = "h" THEN GOSUB NceFunctions 'horn & light on
ELSEIF Key$ = "l" THEN GOSUB NceFunctions 'light on, others off
ELSEIF Key$ = "o" THEN GOSUB NceFunctions 'all functions off
ELSEIF Key$ = "c" THEN GOSUB AutoCircle 'Ramp up & down in circle
ELSEIF Key$ = "d" THEN GOSUB ChgCircleSettings 'new speed & time
ELSEIF Key$ = "p" THEN GOSUB PntToPnt 'Ramp up & down, pt. to pt.
ELSEIF Key$ = "s" THEN GOSUB ChgPtToPtSettings
ELSEIF Key$ = "t" THEN GOSUB TestEyes 'Test light sensitive detectors
ELSE 'None of above = run manual
LOCATE 4: PRINT "4 Exec: Manual Run Mode - Speed Step = "; Spd; SPC(35); "-"
IF LEN(Key$) = 2 THEN '2 chars=arrow pressed
LOCATE 5: PRINT SPC(79); 'clear old msgs from auto loops
A = ASC(RIGHT$(Key$, 1)) 'isolate right character
IF A = 77 THEN Dir = Fwd 'right arrow = forward
IF A = 75 THEN Dir = Rev 'left arrow = reverse
IF A = 72 THEN Spd = Spd + 1 'up arrow = increase speed
IF A = 80 THEN Spd = Spd - 1 'down arrow = decrease speed
GOSUB Nce 'send command to NCE
END IF
END IF
'
Key$ = INKEY$ 'Read keybd; <- = ^K, -> = ^M, ^ = ^H, v= ^P
' need above to reset Key$ after return from auto. sub
LOOP
Exit1: LOCATE 5, 25: PRINT " ## Exiting program (Key$=|" + Key$ + "|) ==========>>"
END
'======8=====================================================================
NceFunctions: 'Send new function command packet to NCE command station
'' Byte3 is the hex of the value of the following bits that are turned on
'' 128 64 32 16 8 4 2 1 <--decimal values
'' 1 0 0 0 4 3 2 1 <-- 0,4,3,2,1 are functions
'' 1 0 0 Lite Dy Brk Cplr Horn Bell
'' 0 4321 <--functions 0 thru 4 bit position
IF Key$ = "b" THEN B3f = 145 ''B3=1001 0001=h91=d145 bell & lights on, others off
IF Key$ = "h" THEN B3f = 146 ''B3=1001 0010=h92=d146 horn & lights on, others off
IF Key$ = "o" THEN B3f = 128 ''B3=1000 0000=h80=d128 all functions off
IF Key$ = "l" THEN B3f = 144 ''B3=1001 0000=h90=d144 lights on, others off
BYTE3f$ = HEX$(B3f)
Ck = B1 XOR B2 XOR B3f
BYTE4$ = HEX$(Ck)
Xmitf$ = "S C05" + " " + BYTE1$ + " " + BYTE2$ + " " + BYTE3f$ + " " + BYTE4$
PRINT #2, Xmitf$:
LOCATE 8, 1: PRINT "8 {.B1...B2...B3f..CK..|.BYTE1.BYTE2.BYTE3f.BYTE4.}"
PRINT "9 {"; B1; B2; B3f; Ck; "| " + BYTE1$ + "...." + BYTE2$ + "...." + BYTE3f$ + "...." + BYTE4$ + "....}"
PRINT "10 { Xmit String='" + Xmitf$ + "' }"
RETURN
'============================================================================
'======8=====================================================================
GetLocoNum: 'Outputs: B1 & B2 (dec), Byte1$ Byte2$ (hex)
Fwd = 96: Rev = 80: Dir = Fwd: Spd = 0 ' Speed range = 0-14
LOCATE 2, 1: PRINT "2 GetLoco: {Enter Loco Cab Number.(Return = 452)...."; : INPUT LN$
IF LN$ = "" THEN LN$ = "0452" 'erie lackawanna #0452
IF LN$ = "u" THEN LN$ = "1862" 'union pacific #1862
IF LN$ = "d" THEN LN$ = "2316" 'd&h u23 #2316
IF LN$ = "h" THEN LN$ = "3333" 'd&h c628 #3333
IF LN$ = "q" THEN GOTO Exit1:
IF LEN(LN$) > 4 THEN LN = 0: GOTO GetLocoNum
LN = VAL(LN$)
LNHEX$ = HEX$(LN)
LEAD0: IF LEN(LNHEX$) < 4 THEN LNHEX$ = "0" + LNHEX$: GOTO LEAD0
BYTE1$ = LEFT$(LNHEX$, 2) ' separate 2 hex bytes.
BYTE2$ = RIGHT$(LNHEX$, 2)
NIBL1$ = LEFT$(BYTE1$, 1): NIBL2$ = RIGHT$(BYTE1$, 1)
' PRINT LNHEX$; " "; BYTE1$; " "; BYTE2$; " "; NIBL1$; " "; NIBL2$
'Pad loco number with 'C000'
IF NIBL1$ = "0" THEN NIBL1$ = "C": GOTO SPLICE
IF NIBL1$ = "1" THEN NIBL1$ = "D": GOTO SPLICE
IF NIBL1$ = "2" THEN NIBL1$ = "E"
SPLICE: BYTE1$ = NIBL1$ + NIBL2$ ' put byte back together
CONVRT: 'Convert Byte1$ Byte2$ (hex) (via Sum) to B1 & B2 (dec) for Xor
BYTE$ = BYTE1$: GOSUB HexDec: B1 = Sum
BYTE$ = BYTE2$: GOSUB HexDec: B2 = Sum
GOSUB Nce 'send command packet to NCE to print direction
'' = = = = = = = = = = = = = = = = = = =''Print values to screen
LOCATE 20
PRINT "20 {lnhex$=" + LNHEX$ + " byte1$/byte2$=" + BYTE1$ + " " + BYTE2$' temporary check on bytes.
LOCATE 2, 1: PRINT SPC(79);
LOCATE 2, 1: PRINT "2 GetLoco: {..Cab # = '" + LN$ + "'..}"
RETURN
'============================================================================
Nce: 'Send new speed/dir command packet to NCE command station
IF Spd < 0 THEN Spd = 0 'Limits Spd range = 0 to 14
IF Spd > 14 THEN Spd = 14
IF Spd = 0 THEN 'Limits Sp2 range = 0, 2 to 15
Sp2 = 0
ELSE
Sp2 = Spd + 1 'Adds 1 to adjust around emer.stop
END IF '(emer. stop =1; need to avoid this)
' = = = = = = = = = = = = = = = = = = =
' This section sends the command to the command station
SPDV = Dir + Sp2
B3 = SPDV: BYTE3$ = HEX$(B3)
Ck = B1 XOR B2 XOR B3
BYTE4$ = HEX$(Ck)
Xmit$ = "Q " + BYTE1$ + " " + BYTE2$ + " " + BYTE3$ + " " + BYTE4$
PRINT #2, Xmit$:
'' = = = = = = = = = = = = = = = = = = =''Print values to screen
LOCATE 3, 1:
IF Dir = Fwd THEN PRINT "3 NCE: Direction= Forward --> , Speed Step="; Spd
IF Dir = Rev THEN PRINT "3 NCE: Direction= <--Reverse , Speed Step="; Spd
LOCATE 21, 1: PRINT "21 {.B1...B2...B3..CK..|.BYTE1.BYTE2.BYTE3.BYTE4.}"
PRINT "22 {"; B1; B2; B3; Ck; "| " + BYTE1$ + "...." + BYTE2$ + "...." + BYTE3$ + "...." + BYTE4$ + "....}"
PRINT "23 { Xmit String='" + Xmit$ + "' }"
RETURN
'============================================================================
HexDec: 'This subroutine converts hex bytes to decimal.' Data to be converted
'enters as BYTE$, is parsed to left and right characters, converted to
'hex by "brute force" lookup, then combined as decimal.
'Data is returned as SUM.
NIBL$ = LEFT$(BYTE$, 1) ' (NIB$ IS VALUE TO CONVERT.)
NIBR$ = RIGHT$(BYTE$, 1)
' let's decimalize the left nibble first.
IF NIBL$ = "A" THEN DECL = 10: GOTO LNIB
IF NIBL$ = "B" THEN DECL = 11: GOTO LNIB
IF NIBL$ = "C" THEN DECL = 12: GOTO LNIB
IF NIBL$ = "D" THEN DECL = 13: GOTO LNIB
IF NIBL$ = "E" THEN DECL = 14: GOTO LNIB
IF NIBL$ = "F" THEN DECL = 15: GOTO LNIB
DECL = VAL(NIBL$) ' this does the digits 0-9
LNIB: DECL = DECL * 16 ' adjust for weight of left hex char.
' now decimalize the right nibble
IF NIBR$ = "A" THEN DECR = 10: GOTO RNIB
IF NIBR$ = "B" THEN DECR = 11: GOTO RNIB
IF NIBR$ = "C" THEN DECR = 12: GOTO RNIB
IF NIBR$ = "D" THEN DECR = 13: GOTO RNIB
IF NIBR$ = "E" THEN DECR = 14: GOTO RNIB
IF NIBR$ = "F" THEN DECR = 15: GOTO RNIB
DECR = VAL(NIBR$) ' this does the digits 0-9
RNIB: ' now we will put the nibbles back together as a decimal value
Sum = DECL + DECR
RETURN
'============================================================================
PntToPnt: 'Automatic Run Point To Point
LOCATE 12, 1
PRINT "12 |--------------------------------------------------------|"
PRINT " | MENU (POINT TO POINT) |"
PRINT " | |"
PRINT " | 'x' to Stop & Return to Manual Control |"
PRINT " | (use 'f' key on Fred's cmptr, while stopped) |"
PRINT " | |"
PRINT " | Stop so one sensor is blocked (do not stop in middle) |"
PRINT "19 |--------------------------------------------------------|"
ON KEY(18) GOSUB BreakPnToPnt: KEY(18) ON 'x key breaks to manual ctl
LOCATE 4: PRINT "4 <- PntToPnt Mode ->"; SPC(40);
LOCATE 4, 25: PRINT "(Top Speed="; SpdPtTop; ") (Stop Time=";
PRINT TimePtStop; ") (Cruise Time="; TimePtCruise; ")"
DO ''''until 'x' key is pressed to break back to Exec & Manual control
LOCATE 5, 61: Cnt2 = Cnt2 + 1: PRINT "(5) Cnt2 ="; Cnt2
'W Snsr '---------------- Test if West sensor is blocked
WSensorBlocked = 0 'reset sensor (0=false, -1=true)
IF Key$ = "w" THEN WSensorBlocked = -1 'special, use w key to FAKE W snsr blkd
IF (INP(port) AND 128) = 128 THEN WSensorBlocked = -1 'W snsr blkd
IF WSensorBlocked THEN 'W snsr blkd,bit 7=1: *1*1111111
LOCATE 6: PRINT SPC(79); : LOCATE 6, 1
PRINT "6 |<|< At West Sensor"
DirNew = Fwd: GOSUB StopStart 'change dir to East
END IF
'E Snsr '---------------- Test if east sensor is blocked
ESensorBlocked = 0 'reset sensor (0=false, -1=true)
IF Key$ = "e" THEN ESensorBlocked = -1 'special, use e key to FAKE E snsr blkd
IF (INP(port) AND 64) = 0 THEN ESensorBlocked = -1 'E snsr blkd
IF ESensorBlocked THEN 'E snsr blkd,bit 6=0: 1*0*111111
LOCATE 6: PRINT SPC(79); : LOCATE 6, 1
PRINT "6"; SPC(55); "At East Sensor >|>|"
DirNew = Rev: GOSUB StopStart 'change dir to West
END IF
'Waiting ''-------------- Waiting for Sensor Input
LOCATE 7, 1: PRINT SPC(79); : LOCATE 7, 1
PRINT "7 (3) Waiting to detect a Sensor blocked (w or e key)"
Key$ = INKEY$ 'Read keybd; <- = ^K, -> = ^M, ^ = ^H, v= ^P
LOOP
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
StopStart:
IF Spd > 0 THEN '' RAMP DOWN (ramp down if engine is moving)
Key$ = "b": GOSUB NceFunctions 'bell & light on
FOR Spd = SpdPtTop TO 0 STEP -1 '===== RAMP DOWN
LOCATE 7, 1: PRINT SPC(79); : LOCATE 7, 1
PRINT "7"; SPC(30); "(4) Ramping Down, Speed Step="; Spd; "of"; SpdPtTop; SPC(15);
GOSUB Nce: SLEEP 1 'send new command packet to NCE
NEXT Spd
Key$ = "l": GOSUB NceFunctions 'light on
''-------------- STOPPED
FOR j = 1 TO TimePtStop
IF TimePtStop - j = 3 THEN Key$ = "h": GOSUB NceFunctions 'horn & light
IF TimePtStop - j = 2 THEN Key$ = "l": GOSUB NceFunctions 'horn off
IF TimePtStop - j = 1 THEN Key$ = "h": GOSUB NceFunctions 'horn & light
LOCATE 7, 1: PRINT SPC(79); : LOCATE 7, 1
PRINT "7"; SPC(45); "(5) Stopped; (StopTime="; j; "of"; TimePtStop; ")"
Key$ = INKEY$ 'Read keybd (Fred's computer only)
IF Key$ = "f" THEN GOSUB BreakPnToPnt 'use for Fred's keyboard
SLEEP 1
NEXT j
Key$ = "l": GOSUB NceFunctions 'light on
END IF
''-------------- RAMP UP (Chg direction & ramp up)
Dir = DirNew: LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
IF Dir = Fwd THEN PRINT "6"; SPC(50); "Eastbound (Forward) ====>"
IF Dir = Rev THEN PRINT "6"; SPC(10); "<==== Westbound (Reverse)"
FOR Spd = 1 TO SpdPtTop '===== RAMP UP
LOCATE 7, 1: PRINT SPC(79); : LOCATE 7, 1
PRINT "7 (1) Ramping Up, Speed Step="; Spd; "of"; SpdPtTop
GOSUB Nce: SLEEP 3 ''send new command packet to NCE
NEXT Spd
''-------------- CRUISE
FOR j = 1 TO TimePtCruise '===== CRUISE
LOCATE 7, 1: PRINT SPC(79); : LOCATE 7, 1
PRINT "7"; SPC(25); "(2) Cruising; time"; j; "of"; TimePtCruise;
SLEEP 1
NEXT j
'''''''LOCATE 7, 1: PRINT SPC(79); '' Clear line
Key$ = "" ''reset or else keeps faking sensor activation
RETURN
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
BreakPnToPnt: LOCATE 6, 1: PRINT SPC(79); : PRINT SPC(79); 'break to Exec. when x key pressed
Spd = 0: GOSUB Nce: Key$ = "": GOTO Exec 'init Key$ to manual Cntl
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
ChgPtToPtSettings: Spd = 0: GOSUB Nce: LOCATE 6, 1 'stop loco for new var's
PRINT "PtToPt Top Speed="; SpdPtTop; "Enter New One or Return to keep"; : INPUT In
LOCATE 7, 1: IF In > 0 THEN SpdPtTop = In
PRINT "PtToPt Stop Time="; TimePtStop; "Enter New One or Return to keep.."; : INPUT In
IF In > 0 THEN TimePtStop = In
PRINT "PtToPt Cruise Time="; TimePtCruise; "Enter New One or Return to keep.."; : INPUT In
IF In > 0 THEN TimePtCruise = In
LOCATE 6, 1: PRINT SPC(79); : PRINT SPC(79); : PRINT SPC(79); 'clear lines
RETURN
'======8=====================================================================
'''' ELSEIF Key$ = "b" THEN GOSUB NceFunctions 'bell & light on
'''' ELSEIF Key$ = "h" THEN GOSUB NceFunctions 'horn & light on
'''' ELSEIF Key$ = "l" THEN GOSUB NceFunctions 'light on, others off
AutoCircle: 'Automatic Ramp Up & Down On Circle ('x' key breaks to Exec)
LOCATE 12, 1
PRINT "12 |--------------------------------------------------------|"
PRINT " | MENU (CIRCLE MODE) |"
PRINT " | |"
PRINT " | 'x' to Stop & Return to Manual Control |"
PRINT " | (use 'f' key on Fred's computer, while stopped |"
PRINT " | |"
PRINT " | (Ramp Down is initiated upon crossing West sensor |"
PRINT "19 |--------------------------------------------------------|"
ON KEY(18) GOSUB BreakCircle: KEY(18) ON 'x key breaks to manual ctl
LOCATE 4: PRINT "4 Circle Mode ->->->"; " (Top Speed="; SpdCirTop;
PRINT ") (Cruise Time="; TimeCirCruise; ") (Stop Time="; TimeCirStop; ")"
Dir = Fwd
DO ''''until 'x' key is pressed to break to Exec & Manual control
LOCATE 5, 61: Cnt2 = Cnt2 + 1: PRINT "(5) Cnt2 ="; Cnt2
''-------------- RAMP UP
FOR Spd = 1 TO SpdCirTop '===== RAMP UP
GOSUB Nce: LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
PRINT "6 (1) Ramping Up, Speed Step="; Spd; "of"; SpdCirTop; SPC(5);
SLEEP 1 'was 4
NEXT Spd
''-------------- CRUISE
FOR j = 1 TO TimeCirCruise '===== CRUISE
LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
PRINT "6", SPC(10); "(2) Cruising; time"; j; "of"; TimeCirCruise; "(speed"; Spd; ")"
SLEEP 1
NEXT j
''-------------- FIND SENSOR
SensorBlocked = 0 'reset sensor (0=false) use -1=true to get past
DO UNTIL SensorBlocked 'cruise until sensor blocked (true= -1)
LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
PRINT "6"; SPC(35); "(3) Waiting to detect West Sensor (w key)"
IF (INP(port) AND 128) = 128 THEN SensorBlocked = -1 'W snsr blkd,bit 7=1: *1*1111111
IF INKEY$ = "w" THEN SensorBlocked = -1 'FAKE W snsr blkd,bit 7=1: *1*1111111
LOOP
''-------------- RAMP DOWN
Key$ = "b": GOSUB NceFunctions 'bell & light on
FOR Spd = SpdCirTop TO 0 STEP -1 '===== RAMP DOWN
GOSUB Nce: LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
PRINT "6"; SPC(40); "(4) Ramping Down, Speed Step="; Spd; "of"; SpdCirTop; SPC(15);
SLEEP 2 'was 4
NEXT Spd
Key$ = "l": GOSUB NceFunctions 'light on
''-------------- STOPPED
FOR j = 1 TO TimeCirStop
IF TimeCirStop - j = 3 THEN Key$ = "h": GOSUB NceFunctions 'horn & light
IF TimeCirStop - j = 2 THEN Key$ = "l": GOSUB NceFunctions 'horn off
IF TimeCirStop - j = 1 THEN Key$ = "h": GOSUB NceFunctions 'horn & light
LOCATE 6, 1: PRINT SPC(79); : LOCATE 6, 1
PRINT "6"; SPC(50); "(5) Stopped; time"; j; "of"; TimeCirStop
Key$ = INKEY$ 'Read keybd - for Fred's computer only
IF Key$ = "f" THEN GOSUB BreakCircle 'use for Fred's keyboard
SLEEP 1
NEXT j
Key$ = "l": GOSUB NceFunctions 'light on
LOOP
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
BreakCircle: LOCATE 6, 1: PRINT SPC(79); : PRINT SPC(79); 'break to Exec. when x key pressed
Spd = 0: GOSUB Nce: Key$ = "": GOTO Exec 'init Key$ to manual Cntl
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
ChgCircleSettings: Spd = 0: GOSUB Nce: LOCATE 6, 1 'stop loco for new var's
PRINT "Circle Top Speed="; SpdCirTop; "Enter New One or Return to keep"; : INPUT In
IF In > 0 THEN SpdCirTop = In: LOCATE 7, 1
PRINT "Circle Cruise Time="; TimeCirCruise; "Enter New One or Return to keep"; : INPUT In
IF In > 0 THEN TimeCirCruise = In: LOCATE 8, 1
PRINT "Circle Stop Time="; TimeCirStop; "Enter New One or Return to keep.."; : INPUT In
IF In > 0 THEN TimeCirStop = In
LOCATE 6, 1: PRINT SPC(79); : LOCATE 7, 1: PRINT SPC(79); : PRINT SPC(79); 'clear lines
RETURN
'============================================================================
' +---Decimal value of INPUT BYTE BEING READ by ?inp(port) command
' | Wst-| |---East Sensor (west snsr is bit 7, east is bit 6)
'1 | | 7 | 6 | 5| 4|3|2|1|0| Bit Position
'2 | |128| 64|32|16|8|4|2|1| Decimal Value Of Each Bit
' | |---|---|--|--|-|-|-|-|
'3* 127 | 0 | 1 | 1| 1|1|1|1|1| Both sensors clear
'5* --- |*1*| 0 | 0| 0|0|0|0|0| West (Left) sensor blocked AND 128 = 128
'7* --- | 0 |*0*| 0| 0|0|0|0|0| East (Right) sensor blocked AND 64 = 0
'============================================================================
TestEyes: 'Verify computer reads light detectors ('s' key breaks to Exec)
ON KEY(18) GOSUB BreakTestEyes: KEY(18) ON 'x key breaks to manual ctl
DO ''''until 'x key is pressed to break back to Exec & Manual control
CLS : LOCATE 3, 1: PRINT "============= Testing Eyes ==============="
IF (INP(port) AND 128) = 128 THEN LOCATE 6, 1: PRINT "West (Left) Sensor Blocked"
IF (INP(port) AND 64) = 0 THEN LOCATE 12, 21: PRINT "East (Right) Sensor Blocked"
LOOP
BreakTestEyes: Key$ = " ": GOTO Exec 'rewrite loco number info
'============================================================================
'UNUSED CODE: ===========================================================================
'============================================================================
''xmit2$ = "S C05 C1 C4 82 87"
''xmit2a$ = "S C05 C1 C4 90 95"
''xmit2b$ = "S C05 C1 C4 80 85"
''PRINT #2, xmit2a$
''PRINT #2, xmit2b$
''ck = c1 XOR c4 XOR 80: PRINT ck
''ck = 193 XOR 196 XOR 130: PRINT ck
(1B01=[an error occurred while processing this directive])
This page created 8/15/01, and last modified 8/16/01