Sub Process_Globals
Public Serial1 As Serial
Private pad As Keypad
Private password As String = "123456" 'the password is *123456
Private passwordBuffer(6) As Byte
Private passwordIndex As Int
Private bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
pad.Initialize("123A456B789C*0#D", Array As Byte(25, 26, 27, 14), Array As Byte(34, 35, 32, 33),"pad_KeyPressed")
'pad.Initialize("123A456B789C*0#D", Array As Byte(32, 33, 25, 26), Array As Byte(36, 39, 34, 35),"pad_KeyPressed")
End Sub
Sub Pad_KeyPressed (Key As String)
Log(Key) 'for debug only
If Key = "*" Then
passwordIndex = 0
'this is not really required, but it makes the logs nicer.
bc.ArrayCopy("000000", passwordBuffer)
Else if passwordIndex < passwordBuffer.Length Then
'put the key in the buffer.
passwordBuffer(passwordIndex) = Asc(Key)
passwordIndex = passwordIndex + 1
If passwordIndex = passwordBuffer.Length Then
If passwordBuffer = password Then
Log("Well done!!!")
End If
End If
End If
Log(passwordBuffer)
End Sub