'  Display the current Operating Mode on the Cylon Eye LEDs  
'
'  Myke Predko
'
'  Copyright (C) 2002 McGraw-Hill
'
' { $STAMP BS2 }


'  Variables
Temp var word				'  Get a 16 Bit Variable


'  Mainline
	high SC				'  Set the I/O Bits As O/P
	high SD				'   and High
        high LED

	OUTS = 52222			'  Make LS 10 Bits Output
	DIRS = 52223			'  And Outputs

Loop:                                   '  Loop here forever
	pause 100			'  Wait 100 msecs between samples
	RobotData = RobotState		'  Read the Operating State
	gosub RobotSendReceive
	OUTS = 52223 ^ RobotData	'  Display the Operating Mode
	goto Loop			'  Repeat Again



'  SumoBot Interface Code Follows
'  
'  Myke Predko
'
'  Copyright (C) 2001 & 2002 McGraw-Hill
'
'  Robot Commands
RobotStop     con  0			'  Stop the Robot
Behavior1     con  1			'  Random Movement
Behavior2     con  2			'  Photovore
Behavior3     con  3			'  Photophobe
Behavior4     con  4			'  Wall Hugger/Maze Solver
RobotForward  con  5			'  Move Forward for 200 msecs
RobotReverse  con  6			'  Move Reverse for 200 msecs
RobotLeft     con  7			'  Turn Left for 200 msecs
RobotRight    con  8			'  Turn Right for 200 msecs
RobotLEDOn    con  9			'  Turn on the Robot's LED
RobotLEDOff   con 10			'  Turn off the Robot's LED
RobotPWM0     con 11			'  PWM = 0% Duty Cycle
RobotPWM1     con 12			'  PWM = 1st "Notch"
RobotPWM2     con 13			'  PWM = 2nd "Notch"
RobotPWM3     con 14			'  PWM = 3rd "Notch"
RobotPWM4     con 15			'  PWM = 100% Duty Cycle
RobotPWM      con 16			'  Return the Current PWM Value
RobotState    con 17			'  Return the Executing State
RobotWhiskers con 18			'  Return State of the "Whiskers"
					'   Bit 0 - Left "Whisker"
					'   Bit 1 - Right "Whisker"
RobotCDSL     con 19			'  Return Value of Left CDS Cell
RobotCDSR     con 20			'  Return Value of Right CDS Cell
RobotButton   con 21			'  Return the Last Remote Button Press
					'   0 - No Buttons Pressed
					'   1 - Leftmost Button Pressed
					'   2 - Middle Button Pressed
					'   3 - Rightmost Button Pressed
					'  After "RobotButton" Operation,  
					'   Button Save is Cleared

'  Robot Interface Pins
LED con 11				'  LED, Negative Active On
RIR con 12				'  Right Infra-Red Detector
LIR con 13				'  Left Infra-Red Detector
SC con 14				'  Define the I/O Pins
SD con 15

'  Robot Interface Variables
RobotData var byte			'  Data Byte to Send to/Receive 
					'   from Robot

'  Robot Operation Subroutines
RobotSend				'  Send the Byte in "RobotData"
	low SC				'  Hold Low for 1 msec before 
	pause 1				'   Shifting in Data
	shiftout SD, SC, LSBFIRST, [RobotData]
	high SC
	return

RobotSendReceive			'  Send the Byte in "RobotData"
	low SC				'  Hold Low for 1 msec before 
	pause 1				'   Shifting in Data
	shiftout SD, SC, LSBFIRST, [RobotData]
	pause 1				'  Wait for Operation to Complete
	shiftin SD, SC, LSBPOST, [RobotData]
	high SC
	return