
Numeric ComPort   = 15
Numeric Bauds     = 1000000

Numeric FirstSlot = 100
Numeric NumBands  = 8

Numeric SweepMin  = 4000 ' 2000 ' 4000
Numeric SweepMax  = 6000 ' 3000 ' 6000
Numeric SweepStep = 30
Numeric DutyCycle = 12

Numeric BeepFrequency = 800
Numeric BeepMillisec  = 10

Numeric TriggerValue = 500

' -----------------------------------
' Resonance frequency
' Bottle NO --- 4780
' Bottle NO --- 5860
' Bottle OK --- 7320 8170

' ----------------------------------- Buttons
Button 1 Label Step+
Button 2 Label Step-
Button 4 Label Duty+
Button 5 Label Duty-
Button 7 Label AdcValue
' ----------------------------------- Load Apps
'Load Theremino_AudioInput.exe
Load Theremino_AudioInOut.exe
Load Theremino_DAA.exe
Load Theremino_SlotViewer.exe
' ----------------------------------- Start
SendOptions
Goto Loop
Stop

Label EventStop
	DutyCycle = 0
	SendOptions
	Button AdcValue Text ""
End

Label Loop
	' ------------------------------- Read Slots
	Numeric Index
	Numeric Value = 0
	For Index = FirstSlot To FirstSlot + NumBands - 1
		Value = Max(Value, Int(Slot(Index)))
	Next
	Button AdcValue Text Value
	' ------------------------------- Test value
	If Value > TriggerValue
		SetAlarm
	Else
		ResetAlarm
	EndIf
	' -------------------------------
	Wait Seconds 0.001
Goto Loop

Label SetAlarm
	Numeric TriggerCommand = 0
	If TriggerCommand <> 1
		TriggerCommand = 1
		AlarmON
		' ---------------------------
		Beep BeepFrequency BeepMillisec 
		' ---------------------------
		Button AdcValue Text " ALARM "
		Button AdcValue Color Flashing8 OrangeRed Green3
		' ---------------------------
		Wait Seconds 0.3
		AlarmOFF
	EndIf
Return

Label ResetAlarm
	TriggerCommand = 0
	Button AdcValue Color Cornsilk
Return

' ----------------------------------- Button execution
Label Step+
	SweepStep = Min(SweepStep + 5, 150)
	SendOptions
Return
Label Step-
	SweepStep = Max(SweepStep - 5, 5)
	SendOptions
Return

Label Duty+
	DutyCycle = Min(DutyCycle + 1, 30)
	SendOptions
Return
Label Duty-
	DutyCycle = Max(DutyCycle - 1, 0)
	SendOptions
Return

' ----------------------------------- Send Options
Label SendOptions
	COM Open ComPort Bauds
	String Cmd = SweepMin + " " + SweepMax + " "
	Cmd = Cmd + SweepStep + " " + DutyCycle + " "
	COM WriteString "OPTIONS " + Cmd  + CRLF
	Print Cmd
	COM Close
Return

' ----------------------------------- Send Commands
Label AlarmON
	COM Open ComPort Bauds
	COM WriteString "ALARM_ON "  + CRLF
	COM Close
Return

Label AlarmOFF
	COM Open ComPort Bauds
	COM WriteString "ALARM_OFF "  + CRLF
	COM Close
Return


'BOOKMARKS 

'EDITEDLINES 112 2 118 2 71 1 104 2 65 3 70 4 10 5 11 6 12 10 13 10 68 10 67 10 

'WATCH v1
'EXEC DestX = 12
