Simple library that monitors keypad key presses.
It is based on the Arduino Keypad library: http://playground.arduino.cc/Code/Keypad
You need to initialize the Keypad with the characters, row pins and column pins. Note that if you are not sure about the order then just connect the pins and try it. Change the pins order in the Initialize method based on the keys that are raised.
Example that waits for a password to be entered:
B4X:
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(9, 8, 7, 6), Array As Byte(5, 4, 3, 2), _
"pad_KeyPressed")
End Sub
Sub Pad_KeyPressed (Key As String)
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