Reply to topic  [ 6 posts ] 
HCMatrixkeypad - Matrix keypad library 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 650
Post HCMatrixkeypad - Matrix keypad library
Description:

This library has been written to be used with our range of matrix keypads. However the library should also work fine with any matrix keypad that matches one of the key arrangements the library supports. The library currently supports the following keypads sold via our web store:

4 x 5 (see SKU: HCPROJ0003)
4 x 4 (see SKU: HCPROJ0001 & HCPROJ0002)
3 x 4 (see SKU: HCPROJ0004)
6 x 1 (see SKU: HCPROJ0007)
4 x 1 (see SKU: HCPROJ0005)

You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area

On Windows:
My Documents\Arduino\libraries\
My Documents\Arduino\libraries\
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/
Documents/Arduino/libraries/
Documents/Arduino/libraries/
or similarly for Linux.

To use the library just include the HCMatrixkeypad.h header file and create one of the following instances of the HCMatrixkeypad library. E.g:

For a keypad with 4 columns and 5 rows:
Code:
HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1, R2, R3, R4, R5);


For a keypad with 4 columns and 4 rows:
Code:
HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1, R2, R3, R4);


For a keypad with 3 columns and 4 rows:
Code:
HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, ROWMARKER, R1, R2, R3, R4);


For a keypad with 4 columns and 1 row:
Code:
HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1);


For a keypad with 6 columns and 1 row:
Code:
HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, C5, C6,  ROWMARKER, R1);


Where:
DEBOUNCE is a decimal value from 1 to 255 which determines the amount of averaging used before a keypress is confirmed.
C1, C2, C3, C4, C5, C6 are the DIO pin numbers used for the keypads columns.
R1, R2, R3, R4, R5 are the DIO pin numbers used for the keypads rows.
ROWMARKER is predefined by the library and is used to separate the column DIO parameters from the row DIO parameters at compile time. This should be left as is.

The following functions are available with this library:

Code:
Keypad.Scan();


Makes one complete scan of the keypad. This must be continuously run in a loop.

Code:
Keypad.New_Key();


Used to test if a new key has been pressed. Returns a boolean true if key had been pressed, or false if no new key has been pressed. If a key has been pressed no further scanning of the keypad will be made until this function is executed.

Code:
Keypad.Ready();


Returns a decimal value of type Byte which indicates the column/row of the last key pressed (0 if no key is currently pressed) where the 10's value indicates the row number and the 1's value indicates the column number. I.e: a value of 53 would indicate that the last key pressed was on Row 5, column 3.

Example Sketch:

Code:
/* FILE:    HCMatrixKeypad.cpp
   DATE:    14/05/14
   VERSION: 0.1
   AUTHOR:  Andrew Davies

This is an example of how to use the the HCMatrixkepday library that has been
written two work with most types of matrix keypads including keypads sold via our
own website.

The current version of library supports the following arrangement (columns x rows)
of keypads:

4 x 5 (see SKU: HCPROJ0003)
4 x 4 (see SKU: HCPROJ0001 & HCPROJ0002)
3 x 4 (see SKU: HCPROJ0004)
6 x 1 (see SKU: HCPROJ0007)
4 x 1 (see SKU: HCPROJ0005)


KEYPAD PINOUTS FOR ABOVE KEYPADS:

PIN....4x5.....4x4.....3x4.....4x1.....6x1
1......R1......C4......C3......C3......C6
2......R2......C3......C2......C4......C5
3......R3......C2......C1......C1......C4
4......R4......C1......R4......C2......C3
5......R5......R4......R3......R1......C2
6......C4......R3......R2..............C1
7......C3......R2......R1..............R1
8......C2......R1........................
9......C1................................


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/

/* Include the HCMatrixkeypad library */
#include <HCMatrixKeypad.h>

/* Sets how many times the same key must be scanned before it is accepted as
   pressed (settled). If you get multiple key presses then increase this value
   (max 255)*/
#define DEBOUNCE 10

#define C1 2  /* DIO for keypad column 1 */
#define C2 3  /* DIO for keypad column 2 */
#define C3 4  /* DIO for keypad column 3 */
#define C4 5  /* DIO for keypad column 4. Delete if there is no column 4! */
#define C5 6  /* DIO for keypad column 5. Delete if there is no column 5! */
#define C6 7  /* DIO for keypad column 6. Delete if there is no column 6! */

#define R1 12 /* DIO for keypad row 1 */
#define R2 11 /* DIO for keypad row 2. Delete if there is no row 2! */
#define R3 10 /* DIO for keypad row 3. Delete if there is no row 3! */
#define R4 9  /* DIO for keypad row 4. Delete if there is no row 4! */
#define R5 8  /* DIO for keypad row 5. Delete if there is no row 5! */

//HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1, R2, R3, R4, R5); /* Uncomment for 4x5 keypad */
//HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1, R2, R3, R4); /* Uncomment for 4x4 keypad */
//HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, ROWMARKER, R1, R2, R3, R4); /* Uncomment for 3x4 keypad */
//HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1); /* Uncomment for 4x1 keypad */
//HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, C5, C6, ROWMARKER, R1); /* Uncomment for 6x1 keypad */


void setup()
{
    Serial.begin(9600);
}

/* Main program */
void loop()
{
  /* Scans the keypad once. This line needs to be run repeatedly */
  Keypad.Scan();
 
  /* Has a new key been pressed  */
  if(Keypad.New_Key())
  {
    /* If so the send the key to the serial port */
    Serial.print("Key Pressed: Row ");
    Serial.print(Keypad.Read() / 10); /* 10's column is the keypad row number */
    Serial.print(" Col ");
    Serial.println(Keypad.Read() % 10); /* 1's column is the keypad column number */
  }
 
}


Library:
Attachment:
HCMatrixKeypad.zip


You do not have the required permissions to view the files attached to this post.


Thu May 15, 2014 10:22 am
Profile

Joined: Fri Oct 14, 2016 5:06 pm
Posts: 2
Post Re: HCMatrixkeypad - Matrix keypad library
Hi admin, you specify the pinout for the I/O pins in the example sketch, but not the power pins. Which is the power and which is the earth (specifically for HCPROJ0002) and are the pins numbered for looking at it from the button side or the back? Thanks.


Fri Oct 14, 2016 5:22 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 658
Post Re: HCMatrixkeypad - Matrix keypad library
Most types of matrix keypads, including the one you have don't require a power supply and so there are no power pins.

For your keypad (HCPROJ0002), if you orientate it so that the buttons are facing you with the connector at the bottom of the keypad the pinout from left to right is as follows:


1) Not connected
2) Col 1
3) Col 2
4) Col 3
5) Col 4
6) Row 1
7) Row 2
8) Row 3
9) Row 4
10) Not connected

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Sat Oct 15, 2016 9:25 am
Profile

Joined: Fri Oct 14, 2016 5:06 pm
Posts: 2
Post Re: HCMatrixkeypad - Matrix keypad library
OK, Thanks! :)


Sat Oct 15, 2016 6:54 pm
Profile

Joined: Wed Oct 19, 2016 12:46 am
Posts: 1
Post Re: HCMatrixkeypad - Matrix keypad library
thank you.


Wed Oct 19, 2016 12:51 am
Profile

Joined: Tue Oct 18, 2016 5:46 pm
Posts: 1
Post Re: HCMatrixkeypad - Matrix keypad library
thank you


Tue Nov 29, 2016 1:10 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD