Skip to content

Commit 0cbb4c0

Browse files
authored
Add files via upload
1 parent af8ce8e commit 0cbb4c0

12 files changed

+1091
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# UART Keyboard Library For Arduino
2+
3+
---
4+
5+
## Overview
6+
7+
BC6xxx and BC759x series chips share a unified single line UART keyboard interface. This library can be used for the following chips:
8+
9+
- BC6301 -- 30-key key matrix interface
10+
11+
- BC6040 -- 40-key key matrix interface
12+
13+
- BC6561 -- 56-key key matrix interface
14+
15+
- BC6088 -- 88-key key matrix interface
16+
17+
- BC7595 -- 6 digits 7-segment LED display with 48-key key matrix driver
18+
19+
- BC7591 -- 32 digits 7-segment LED display with 96-key key matrix driver
20+
21+
This library is available for all Arduino devices, and can be used for both hardware and software serial ports.
22+
By using this library, in addition to easily handling common single-key events, complex keyboard functions such as key combinations and long-press keys can be implemented with just a few lines of code.
23+
In the UART single line keyboard interface, a keyboard event is represented by a single byte each time. Value 0-0x7F represents the key number value, the highest bit is used as a key release flag, that is, value 0-0x7F means the key is pressed, 0x80-0xFF means the key is released, so theoretically the maximum number of keys is 128. In reality the BC7591 can support up to 96 keys. This library uses the unused key number space to allow users to assign combination keys and long-press keys a custom key number, so that in the user program, handling of combination keys and long-press keys is as simple as the handling of ordinary keys, everything else is handled by the library.
24+
The library is very simple to use, requiring only 3 steps.
25+
26+
1. In loop(), call the checkChanges() function.
27+
28+
2. query isKeyChanged()
29+
30+
3. If the result of isKeyChanged() is true, use getKeyValue() to get the key value
31+
32+
For detailed information about the UART keyboard interface, please refer to the datasheet of the BC6xxx or BC759x series chips.
33+
34+
## Library Installation
35+
36+
This library is available in Arduino Library Manager, can be also installed using the zip file downloaded, just goto "Sketch-->Include Library-->Add .ZIP Libaray..."
37+
38+
## Hardware Connection
39+
40+
The BC6xxx and BC759x series chips both use UART serial communication, and the UART uses 2 pins TX and RX on the chip, where TX is the output of the chip's keyboard interface. The BC6xxx chip does not have RX pins, they are only available on the BC759x, which is used for the LED driver. When connected, the TX/RX pins of the chip are cross-connected with the RX/TX pins of the Arduino serial port.
41+
42+
![](./extras/img/serial_port_connection.png)
43+
44+
More detailed information about this library please see : [usage](./extras/docs/usage.md)
45+
46+
Or for the PDF version of complete user manual in [简体中文](./extras/docs/BC6xxx_BC759x_UART_Keyboard_Arduino_Library_cn.pdf) or [English](./extras/docs/BC6xxx_BC759x_UART_Keyboard_Arduino_Library.pdf)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/******************************************************************************
2+
* longpress.ino
3+
* BC6xxx & BC759x Key Scan Interface Library Example Code
4+
*
5+
* This code uses Serial1 to connect a BC6xxx or BC759x chip. it can
6+
* detect key presses.
7+
* Serial is also used to communicate with computer. When a key is
8+
* pressed, the key value is printed to the Serial port so can be
9+
* seen with the Arduino Serial Monitor
10+
* This code runs on any Arduino compatible boards.
11+
*
12+
* Dependencies:
13+
* This code depends on the following libraries:
14+
* Arduino Software Serial Library
15+
* UART_Keyboard_Driver Library
16+
*
17+
* Author:
18+
* This software is written by BitCode. https://bitcode.com.cn
19+
*
20+
* Version:
21+
* V1.0 March 2021
22+
* V2.0 May 2021. Changed to use Serial to print key value
23+
* V3.0 October 2024. Changed default keyboard port to Serial1
24+
*
25+
* License:
26+
* MIT license. It can be used for both open source and commercial projects.
27+
******************************************************************************/
28+
#include <UART_Keyboard.h>
29+
30+
#define KEYBOARD_SERIAL Serial1 // By default this code uses Serial1 as keyboard port
31+
// If you are using Arduino with only 1 Serial (such as UNO), you may want to disable
32+
// the above line and use the following setting:
33+
// #include <SoftwareSerial.h>
34+
// #define KEYBOARD_SERIAL swSerial
35+
// SoftwareSerial swSerial(11, 12); // creating SoftwareSerial instance, using pin 11 as Rx, 12 as Tx (Tx not used in this example)
36+
37+
UartKeyboard Keypad(KEYBOARD_SERIAL); // creating UartKeyboard instance
38+
39+
40+
void setup() {
41+
Serial.begin(115200); // Initialize Serial for monitoring
42+
KEYBOARD_SERIAL.begin(9600); // Initialize keyboard serial port
43+
}
44+
45+
void loop() {
46+
Keypad.checkChanges(); // let the key scan library to update key status
47+
if (Keypad.isKeyChanged() == true) { // if there is any detectable key change
48+
Serial.println(Keypad.getKeyValue()); // print key value on Serial (use Serial Monitor to see it!)
49+
}
50+
// put your main code here, to run repeatedly:
51+
delay(50); // delay 50ms
52+
}

examples/longpress/longpress.ino

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/******************************************************************************
2+
* longpress.ino
3+
* BC6xxx & BC759x Key Scan Interface Library Example Code
4+
*
5+
* This code uses Serial1 to connect a BC6xxx or BC759x chip. Besides
6+
* normal single key pressing, it can also detect the long-press of particular
7+
* keys.
8+
* Serial port is used to print the keypad detection results.
9+
* This software monitors keypad actions and print key values on Serial. When key
10+
* 1 or key 5 is pressed for more than 3s, a new key event with user defined key
11+
* value of 120(0x78) or 121(0x79) is generated.
12+
* This code runs on any Arduino compatible boards.
13+
*
14+
* Dependencies:
15+
* This code depends on the following libraries:
16+
* Arduino Software Serial Library
17+
* UART_Keyboard_Driver Library
18+
*
19+
* Author:
20+
* This software is written by BitCode. https://bitcode.com.cn
21+
*
22+
* Version:
23+
* V1.0 March 2021
24+
* V2.0 May 2021, changed to use hardware Serial to print key values.
25+
* V3.0 October 2024. Changed default keyboard port to Serial1
26+
*
27+
* License:
28+
* MIT license. It can be used for both open source and commercial projects.
29+
******************************************************************************/
30+
#include <UART_Keyboard.h>
31+
32+
#define KEYBOARD_SERIAL Serial1 // By default this code uses Serial1 as keyboard port
33+
// If you are using Arduino with only 1 Serial (such as UNO), you may want to disable
34+
// the above line and use the following setting:
35+
// #include <SoftwareSerial.h>
36+
// #define KEYBOARD_SERIAL swSerial
37+
// SoftwareSerial swSerial(11, 12); // creating SoftwareSerial instance, using pin 11 as Rx, 12 as Tx (Tx not used in this example)
38+
39+
UartKeyboard Keypad(KEYBOARD_SERIAL); // creating UartKeyboard instance
40+
41+
// Definition of long-press keys
42+
const unsigned char lp1[2] = { 1, 120 }; // Longpress key 1, detecting long-pressing of key 1 and use 120 as the user defined key value
43+
const unsigned char lp2[2] = { 5, 121 }; // Longpress key 2, detecting long-pressing of key 5 and use 121 as the user defined key value
44+
const unsigned char* LPList[2] = { lp1, lp2 }; // Longpress key list
45+
46+
void setup() {
47+
Serial.begin(115200); // Initialize Serial for monitoring
48+
KEYBOARD_SERIAL.begin(9600); // Initialize keyboard serial port
49+
Keypad.defLongpressKey(LPList, 2); // Define long-press keys
50+
Keypad.setLongpressCount(60); // Set long-press time to 3s (50ms * 60)
51+
}
52+
53+
void loop() {
54+
Keypad.checkChanges(); // let the key scan library to update key status
55+
if (Keypad.isKeyChanged() == true) { // if there is any detectable key change
56+
Serial.println(Keypad.getKeyValue()); // print key value on Serial (use Serial Monitor to see it!)
57+
}
58+
Keypad.longpressTick(); // Tick the long-press detector in BC_key_scan library
59+
// put your main code here, to run repeatedly:
60+
delay(50); // delay 50ms
61+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/******************************************************************************
2+
* longpress_combined.ino
3+
* BC6xxx & BC759x Key Scan Interface Library Example Code
4+
*
5+
* This code uses Serial1 to connect a BC6xxx or BC759x chip. Besides
6+
* normal single key pressing, it can also detect the long-press of particular
7+
* keys or the combination of multiple keys.
8+
* Serial is used to print the key detection results. Use the IDE built-in
9+
* Serial Monitor to see outputs.
10+
* This software prints the key value on Serial when there is a key event.
11+
* When key 1 or key 5 is pressed for more than 3s, a new key event with user
12+
* defined key value of 120(0x78) and 121(0x79) is generated.
13+
* When key 0 and key 1 are pressed simutaneously, a new key event for this
14+
* combined key with key value of 122(0x7a) is generated. Also for a combination
15+
* of key 8 and key 12, with key value of 123(0x79).
16+
* This code runs on any Arduino compatible boards.
17+
*
18+
* Dependencies:
19+
* This code depends on the following libraries:
20+
* Arduino Software Serial Library
21+
* UART_Keyboard_Driver Library
22+
*
23+
* Author:
24+
* This software is written by BitCode. https://bitcode.com.cn
25+
*
26+
* Version:
27+
* V1.0 March 2021
28+
* V2.0 May 2021, changed print output to use built-in Serial.
29+
* V3.0 October 2024. Changed default keyboard port to Serial1
30+
*
31+
* License:
32+
* MIT license. It can be used for both open source and commercial projects.
33+
******************************************************************************/
34+
#include <UART_Keyboard.h>
35+
36+
#define KEYBOARD_SERIAL Serial1 // By default this code uses Serial1 as keyboard port
37+
// If you are using Arduino with only 1 Serial (such as UNO), you may want to disable
38+
// the above line and use the following setting:
39+
// #include <SoftwareSerial.h>
40+
// #define KEYBOARD_SERIAL swSerial
41+
// SoftwareSerial swSerial(11, 12); // creating SoftwareSerial instance, using pin 11 as Rx, 12 as Tx (Tx not used in this example)
42+
43+
UartKeyboard Keypad(KEYBOARD_SERIAL); // creating UartKeyboard instance
44+
45+
46+
// Definition of long-press keys
47+
const unsigned char lp1[2] = { 1, 120 }; // Longpress key 1, detecting long-pressing of key 1 and use 120 as the user defined key value
48+
const unsigned char lp2[2] = { 5, 121 }; // Longpress key 2, detecting long-pressing of key 5 and use 121 as the user defined key value
49+
const unsigned char* LPList[2] = { lp1, lp2 }; // Longpress key list
50+
51+
// Definition of combined keys
52+
const unsigned char cb1[4] = { 2, 122, 0, 1 }; // Combined key 1, combination of 2 keys: key0 and key1, use 122 as user defined key value
53+
const unsigned char cb2[4] = { 2, 123, 8, 12 }; // Combined key 2, combination of 2 keys: key8 and key12, use 123 as user defined key value
54+
const unsigned char* CBList[2] = { cb1, cb2 }; // Combined key list
55+
56+
void setup() {
57+
Serial.begin(115200); // Initialize Serial for monitoring
58+
KEYBOARD_SERIAL.begin(9600); // Initialize software serial swSerial
59+
Keypad.defLongpressKey(LPList, 2); // Define long-press keys
60+
Keypad.setLongpressCount(60); // Set long-press time to 3s (50ms * 60)
61+
Keypad.defCombinedKey(CBList, 2); // Define combined keys
62+
}
63+
64+
void loop() {
65+
// put your main code here, to run repeatedly:
66+
Keypad.checkChanges(); // let the key scan library to update key status
67+
if (Keypad.isKeyChanged()) // if there is any detectable key change
68+
{
69+
Serial.println(Keypad.getKeyValue()); // print key value on Serial (use Serial Monitor to see it!)
70+
}
71+
Keypad.longpressTick(); // Tick the long-press detector in BC_key_scan library
72+
delay(50); // delay 50ms
73+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)