B4R Library Keypad


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:
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
   pad.Initialize("123A456B789C*0#D", Array As Byte(9, 8, 7, 6),  Array As Byte(5, 4, 3, 2), _
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
End Sub


  • rKeypad.zip
    9.3 KB · Views: 652


Well-Known Member
Licensed User
how can I use this library with 3x4 keypad, just remove last element from array?


Well-Known Member
Licensed User
I tried your example with 4x4 keypad, but I've got no response at all, except this message at start up, I tried also to change pin assignment without any success!



Well-Known Member
Licensed User
Longtime User
Same as @Mostez on B4Rv1.20 - B4R1.50 with old Arduino IDE

Works ok updating Arduino IDE to 1.6.11 as stated on B4R page docs

vali khandangoll

Active Member
hi all of you.
My B4R compiler read BC variable with error like attached picture.
my you help me ?


  • key error.jpg
    key error.jpg
    197.3 KB · Views: 335