![]() |
ByVac I2C Keypad Library For Arduino
Well, it took a little hair pulling, but I finally created my own library for the arduino. I had recently bought an I2C keypad on ebay from ByVac because I made a mistake (I wanted one to hook up to the LCD controller). Without further ado, here's the library.
ByVac I2C Keypad Library
Once you've finished downloading it just put it in your hardware/libraries directory.
There are only 3 functions available:
- numkeys (find if there are keys in buffer)
- keydown (returns 1 if a key is down)
- getkey (get the number of the key that was pressed
Usage is as follows:
#include <Wire.h> // i2c
#include <ByVacKeypad.h> // library for byvac i2c keypad
// default is 0x62 which is 8 bits, 0x31 is 7 bit address
ByVacKeypad keypad = ByVacKeypad(0x31);
void setup() {
keypad.init(); // initialize the keypad. just clears buffer
Serial.begin(9600);
}
void loop(){
Serial.print("Keys in Buffer: ");
int numkeys;
Serial.print(numkeys);
delay(2000);
if(keypad.numkeys() > 0){
Serial.print("Key Pushed: ");
int getkey = keypad.getkey();
Serial.print(getkey);
}
delay(2000);
if(keypad.numkeys() > 0){
Serial.print("Key Down: ");
int keydown = keypad.keydown();
Serial.print(keydown);
// will return 1 if key is down and 0 otherwise
}
}One important thing to remember is the library will only retrieve one key push at a time and than it clears the buffer. The buffer can hold 16 keys, but for my purposes I only needed to get one key value at a time. If you need it changed or know how to change it let me know and I'll update it here as well.
Any questions or comments feel free to leave. Enjoy.
- Content:
- Tags:

