'  Hello World - Print Message Indicating that Robot is Executing
'
'  Myke Predko
'
'  Copyright (C) 2001 McGraw-Hill
'
' { $STAMP BS2 }


'  Mainline
	high SC				'  Set the I/O Bits As O/P
	high SD				'   and High

	debug "Hello World!", cr	'  Output Debug Message

	end					'  Nothing more to do



'  Robot Interface Code Follows:
'  
'  Myke Predko
'
'  Copyright (C) 2001 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 the State of the "Whiskers"
						'   Bit 0 - Left "Whisker"
						'   Bit 1 - Right "Whisker"
RobotCDSL     con 19			'  Return the Value of the Left CDS Cell
RobotCDSR     con 20			'  Return the Value of the Right CDS Cell
RobotButton   con 21			'  Return the Last Remote Button Pressed
						'   0 - No Buttons Pressed
						'   1 - Leftmost Button Pressed
						'   2 - Middle Button Pressed
						'   3 - Rightmost Button Pressed
						'  After "RobotButton" Operation, Button 
						'   Save in Robot is Cleared

'  Robot Interface Pins
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 2				'  Wait for Operation to Complete
	shiftin SD, SC, LSBPOST, [RobotData]
	high SC
	return