'---------------------------------------------------------------------
' File name:  WXM_600E_Seq_3.txt                     Date: 11 May 2020
'---------------------------------------------------------------------
' MicroStepper stepper  step for run
'---------------------------------------------------------------------
' Encoder 200 ppr
' HAL recognize 800 ppr
' Stepper 1.8 degree
' Step per full turn = 800 (jumper on B)
'----------------------------------------------------------------------

'Load POC.jpg
Option Speed 9

Button  1 Text "HOME"
Button  1 Color SkyBlue
Button  2 Text "Homing_M0"
Button  2 Color SkyBlue
Button  3 Text "Homing_M1"
Button  3 Color SkyBlue
Button  4 Text "Homing_M2 Z"
Button  4 Color SkyBlue
Button  5 Text "SCIUSCIA M0"
Button  5 Color Aquamarine
Button  6 Text "SCIUSCIA M1"
Button  6 Color Aquamarine
Button  7 Text "SCIUSCIA M2 Z"
Button  7 Color Aquamarine

Button 12 Text "Sciuscia tune"
Button 12 Color Aquamarine

Button 13 Text "Enable Motors"
Button 13 Color Tan
Button 14 Text "Disable Motors"
Button 14 Color Tan

'Button 15 Text "UPDATE FILE"

Button 16 Text "CLOSE ALL"
Button 16 Color Red

Key Right		Gosub MoveRight
Key Left 		Gosub MoveLeft
Key Up 			Gosub MoveUp
Key Down 		Gosub MoveDown
Key Pageup		Gosub MoveUpper
Key Pagedown	Gosub MoveLower
Key M			Gosub "Enable Motors"

Variable Numeric NumMotors
Variable Numeric Slot_M0
Variable Numeric Slot_M1
Variable Numeric Slot_M2
Variable Numeric Slot_M3
Variable Numeric Slot_M4
Variable Numeric Slot_M5
Variable Numeric Slot_M6
Variable Numeric Slot_M7
Variable Numeric Slot_M8
Variable Numeric Slot_SensorM0
Variable Numeric Slot_SensorM1
Variable Numeric Slot_SensorM2
Variable Numeric Slot_CounterReaderOutM0
Variable Numeric Slot_CounterReaderOutM1
Variable Numeric Slot_CounterReaderOutM2
Variable Numeric Slot_CounterReaderOutM3
Variable Numeric Slot_CounterReaderOutM4
Variable Numeric Slot_CounterReaderOutM5
Variable Numeric Slot_CounterReaderOutM6
Variable Numeric Slot_CounterReaderOutM7
Variable Numeric Slot_CounterReaderOutM8
Variable Numeric Slot_CounterReaderResetM0
Variable Numeric Slot_CounterReaderResetM1
Variable Numeric Slot_CounterReaderResetM2
Variable Numeric Slot_CounterReaderResetM3
Variable Numeric Slot_CounterReaderResetM4
Variable Numeric Slot_CounterReaderResetM5
Variable Numeric Slot_CounterReaderResetM6
Variable Numeric Slot_CounterReaderResetM7
Variable Numeric Slot_CounterReaderResetM8
Variable Numeric Slot_EnableMotors
Variable Numeric Slot_LedR
Variable Numeric Slot_LedG
Variable Numeric Slot_LedB


NumMotors = 3
Slot_M0 = 1
Slot_M1 = 3
Slot_M2 = 5

Slot_SensorM0 = 19
Slot_SensorM1 = 20
Slot_SensorM2 = 21

Slot_CounterReaderOutM0 = 26
Slot_CounterReaderResetM0 = 25

Slot_CounterReaderOutM1 = 28
Slot_CounterReaderResetM1 = 27

Slot_CounterReaderOutM2 = 30
Slot_CounterReaderResetM2 = 29

Slot_EnableMotors = 22

Slot_LedR = 16
Slot_LedG = 17
Slot_LedB = 18

Variable Numeric NumTest
Variable Numeric NumCycles
Variable Numeric ErrorNumber

Variable String FileName
Variable String FileHeader

FileName = "Log_Encoder_0_200.txt"
FileHeader = "- DATE - " + "  - TIME - " + "  CYCLE " + " Dest.=0 " + " Dest.=50 " + + " Pulse"
Save StringToFile FileHeader FileName


' -------------------------------------- LOAD EXTERNAL PROGRAMS
Load "Theremino_HAL\Theremino_HAL.exe"
Load "Theremino_HAL\Theremino_SlotViewer.exe"
Load "Theremino_HAL\Theremino_CounterReader1.exe"
Load "Theremino_HAL\Theremino_CounterReader2.exe"
'Load "Theremino_HAL\Theremino_CounterReader3.exe"

' ---------------------------------------------- TEST MASTER PRESENT
For v1 = 1 To 9e99
	For v2 = 1 To 20 ' <<< testing for 2 seconds
		If (Slot(0) >= 1 And Slot(0) <= 2) Or Key("CTRL")
			Exit 2
		EndIf
		Wait Seconds 0.1
	Next
	Print " Invalid master number: " + Slot(0)
	Slot 0 = Recognize
	Beep
Next
Print ""


' -------------------------------------- COLOR

'Gosub "WHITE"
'Wait Seconds 0.1
'Gosub "RED"
'Wait Seconds 0.1
'Gosub "GREEN"
'Wait Seconds 0.1
'Gosub "BLU"
'Wait Seconds 0.1

Stop



'WATCH SequenceCmd
'WATCH s1
'WATCH UCase(SequenceCmd)
