
'===================================================================
'  RECOLOR SPEED TESTER - 200 LINES
'===================================================================

' ------- ColorAllLines_StartingWith                         mS
' ------- ColorAllLines_StartingWith_And_Containing      100 mS
'Label pippo
'Return

' ------- ColorAllLines_StartingWith                      64 mS
For v1 = 0 To 9
	
Next

' ------- ColorAllLines_StartingWith                      50 mS
Variable String Test							 'Breakpoint
Variable String Result							 'Breakpoint

' ------- ColorAllLines_StartingWith                      80 mS
If v1 = v2
EndIf


Button 1 Text Start		' this is start			 'Breakpoint
Button 2 Text "PMW 000"							 'Breakpoint
Button 3 Text "PMW 250"
Button 4 Text "PMW 350"
Button 5 Text "PMW 450"							 'Breakpoint
Button 6 Text "PMW 600"
Button 7 Text "PMW 750"
Button 8 Text "PWM 999"							 'Breakpoint

Load Theremino_HAL\Theremino_HAL.exe
Load Theremino_HAL\Theremino_SlotViewer.exe
Load Theremino_HAL\Theremino_SignalScope.exe
Load Theremino_HAL\Theremino_AudioGenerator.exe

Key 5 			Gosub Red
Key Right		Gosub Yellow
Key Left 		Gosub Green
Key Up 			Gosub ColorOff
Key Down 		Gosub ReadCounter
Key Pageup		Gosub ResetCounter
Key Pagedown	Gosub Sounds
Key M			Gosub Colors

' ------- ColorAllLines_StartingWith                100..200 mS
' ------- ColorAllLines_StartingWith_And_Containing  50..100 mS
Label MainLoop
	Wait Seconds 0.01
	'
	v1 = v1 + 1
	If v1 > 50
		v1 = 0
		Gosub ColorOff
	EndIf
	If v1 > 49
		Gosub Green
	EndIf
	'
	If	Slot(6) > 500
		Gosub Start
	EndIf
Goto MainLoop

Label Start
	Slot(1) = 0		'stop motor
	v1 = 250   		'start motor move
	Gosub ResetCounter
	Gosub ReadCounter ' Counter = V9
	v2 = v9 + 5500
	Label Loop
		Wait Seconds 0.01
		v1 = v1 + 1
		Slot(1) = v1
		Gosub readcounter ' Counter = V9
		' ------------------------------------- too much counts
		If v2 <= v9
			Slot(1) = 0
			Slot(13) = 0
			v1 = 0
			Return
		EndIf
		Gosub Sounds
		Gosub Colors
		' ------------------------------------- too much current
		If Slot(4) > 8000
			Slot(1) = 0
			Gosub Red
			v1 = 0
			Return
		EndIf
	Goto Loop
Return



Label "PMW 000"
	Slot(1) = 0
Return

Label "PMW 250"
	Slot(1) = 250
Return

Label "PMW 350"
	Slot(1) = 350
Return

Label "PMW 450"
	Slot(1) = 450
Return

Label "PMW 600"
	Slot(1) = 600
Return

Label  "PMW 750"
	Slot(1) = 750
Return

Label  "PWM 999"
	Slot(1) = 999
Return

'---------------------------------------------------------------------------------
'----- subroutine area -----------------------------------------------------------
'---------------------------------------------------------------------------------
Label Red
	Slot(7) = 1000		'red
	Slot(8) = 0			'yellow
	Slot(9) = 0			'green
Return

Label Yellow
	Slot(7) = 0			'red
	Slot(8) = 1000		'yellow
	Slot(9)	= 0			'green
Return

Label Green
	Slot(7) = 0			'red
	Slot(8) = 0			'yellow
	Slot(9) = 1000		'green
Return

Label ColorOff
	Slot(7) = 0			'red
	Slot(8) = 0			'yellow
	Slot(9) = 0			'green
Return


' -------------------------------------------------------------
'  The counter is V9 -  USE V9 IN YOUR CODE
'  Do not use v7 and v8 in your code
' -------------------------------------------------------------
Label ReadCounter
	v8 = Slot(11)   	' new hardware value
	v9 = v9 + (v8 - v7)	' upDate the counter (V9) with the difference
	If v8 < v7 - 16387	' If new hardware value < old hardware value - 1/4 range
		v9 = v9 + 65536	' then increase the counter (V9)
	EndIf
	v7 = v8				' old hardware value = new hardware value
Return

Label ResetCounter
	v9 = 0   		' User counter value (V9)
	v8 = Slot(11)	' new hardware value
	v7 = v8   		' old hardware value
Return

Label Sounds
	If Slot(4) > 3500
		Slot(13) = 500 + (Slot(4) - 3500) * 0.5
	Else
		Slot(13) = 0
	EndIf
Return

Label Colors
	Select True
		Case  Slot(4) > 6000
			Gosub Red
		Case  Slot(4) > 3500
			Gosub Yellow
		CaseElse
			Gosub Green
	EndSelect
Return



'====== DUMMY AREA ===============================================================
' pippo test result  Start "PMW 000" loop
'====== TO DO AREA ===============================================================


'EXEC Slot(2) = 0
