#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
' planned screen
'
' (A) Speed Down: 20 mm/s
' (B) Hold Time: 10 mins
' (C) Speed Up: 40 mm/s
' (D) Run (*) Reset
Sub Process_Globals
Dim Serial1 As Serial
Dim pad As Keypad
Dim KeyBuffer(6) As Byte
Dim vKey As Int=0
Dim SpeedDown As Long=0
Dim Holdtime As Long=0
Dim Speedup As Long=0
Dim timer1 As Timer
Dim CommandActive As UInt=0
Dim bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
pad.Initialize("123A456B789C*0#D", Array As Byte(9, 8, 7, 6), Array As Byte(5, 4, 3, 2), _
"pad_KeyPressed")
timer1.Initialize("timer1_Tick",1000)
End Sub
Sub timer1_Tick
End Sub
Sub Pad_KeyPressed (Key As String)
If Key = "*" Then
SpeedDown=0
Holdtime=0
Speedup=0
'ResetDisplay
Else if Key = "A" Then
'Speed down
If CommandActive>0 Then Return ' a different command key is active
CommandActive=1
Log("Speed down active ....")
vKey=0
Else if Key = "B" Then
'Hold time
If CommandActive>0 Then Return
CommandActive=2
Log("Hold time active ....")
vKey=0
Else if Key = "C" Then
'Speed up
If CommandActive>0 Then Return
CommandActive=3
Log("Speed up active ....")
vKey=0
Else if Key = "D" Then
'Run
Log(CRLF, "Show all values")
Log("Speed down: ", SpeedDown, " mm/s")
Log("Hold time: ", Holdtime)
Log("Speed up: ", Speedup, " mm/s", CRLF)
else if Key = "#" Then
'Enter pressed
Select Case CommandActive
Case 1
Log("Speed down changed")
SpeedDown=bc.StringFromBytes(KeyBuffer)
Log("Speed down is now: ", SpeedDown, " mm/s")
CommandActive=0
ClearKeyBuffer
Case 2
Holdtime=bc.StringFromBytes(KeyBuffer)
Log("Hold time changed")
CommandActive=0
ClearKeyBuffer
Case 3
Speedup=bc.StringFromBytes(KeyBuffer)
Log("Speed up changed")
CommandActive=0
ClearKeyBuffer
End Select
else if vKey<6 Then
'put the key in the buffer.
KeyBuffer(vKey)= Asc(Key)
Log("Key: ", vKey, " Value: ", Key)
vKey=vKey+1
End If
End Sub
Sub ClearKeyBuffer
Log("KeyBuffer before clear: ", KeyBuffer)
For i=0 To KeyBuffer.Length-1
KeyBuffer(i)=Asc(" ")
Next
Log("KeyBuffer after clear: ", KeyBuffer)
End Sub