	LaunchTask	StopWatch
	RunTasksForever

;----- StopWatch task ---------
;I/O is set up for an MMi201
iSW_StartButton		iEQU	12
iSW_StopButton		iEQU	11
iSW_ResetButton		iEQU	10

SW_Timer	defTIME24	;Reserve RAM for the stopwatch timer

StopWatch:
SW_Set0:
	OBLCD_SetCur	0,0
	OBLCD_Text	"  0.00"		;Clear stopwatch display
SW_0:
	ResetK					;Clear Key latches
	WaitOnK		iSW_StartButton		;Wait for start command
SW_Set1:
	STStart		SW_Timer		;Start timing
	ResetK					;Clear Key latches

;Main timing..
;While the SuperTimer takes care of the actual timing, we monitor
;the stop button, breaking off every 100mS to update the display.
SW_1:	
	WaitOnKT	iSW_StopButton,10	;100mS
	GoIfT		SW_Set2			;G/ button was pressed
	GoSub		SW_Display		;Update the display
	GoTo		SW_1			;Keep watching the button

;Here when user hits the stop button
SW_Set2:
	ResetK					;Clear Key latches
	GoSub		SW_Display		;Display final time
SW_2:
	WaitOnK		iSW_ResetButton		;Wait for reset
	GoTo		SW_Set0			;Repeat

;Subroutine to grab and display elapsed stopwatch time
SW_Display:
	fSTTimeSince	SW_Timer		;Get time
	fLoadQ		0.01			;10mS increments
	fMul					;Scale to seconds
	OBLCD_SetCur	0,0
	OBLCD_fDispW	6,2
	Return