B4R Library Keypad

Discussion in 'B4R Libraries' started by Erel, Oct 30, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User


    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(6As Byte
    Private passwordIndex As Int
    Private bc As ByteConverter
    End Sub

    Private Sub AppStart
    "123A456B789C*0#D"Array As Byte(9876),  Array As Byte(5432), _
    End Sub

    Sub Pad_KeyPressed (Key As String)
    If Key = "*" Then
         passwordIndex = 
    '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 + 
    If passwordIndex = passwordBuffer.Length Then
    If passwordBuffer = password Then
    Log("Well done!!!")
    End If
    End If
    End If
    End Sub

    Attached Files:

  2. Mostez

    Mostez Active Member

    sure, it is

    Thanks Erel
  3. Mostez

    Mostez Active Member

    how can I use this library with 3x4 keypad, just remove last element from array?
  4. Erel

    Erel Administrator Staff Member Licensed User

    You need to pass a 12 character string and remove the last element from one of the arrays (which one depends on the keypad structure). Run some tests and you will find out which one needs to be removed.
    Mostez likes this.
  5. Mostez

    Mostez Active Member

    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!

  6. Erel

    Erel Administrator Staff Member Licensed User

  7. inakigarm

    inakigarm Well-Known Member Licensed 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
  8. Mostez

    Mostez Active Member

  9. Mostez

    Mostez Active Member

    it works OK now, tested with 3 col X 4 rows keypad
  10. Peter Simpson

    Peter Simpson Expert Licensed User

    Thank you @Erel, your code works perfect....
  11. hi all of you.
    My B4R compiler read BC variable with error like attached picture.
    my you help me ?

    Attached Files:

  12. Erel

    Erel Administrator Staff Member Licensed User

    You need to select rRandomAccessFile library.
  13. thanks. sloved
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice