Emakefun Matrix Keyboard Arduino 库 1.0.1
载入中...
搜索中...
未找到
get_current_pressed_key.ino
浏览该文件的文档.
1/**
2 * @~Chinese
3 * @file get_current_pressed_key.ino
4 * @brief 示例:获取当前按下的按键值若有多个按键按下则返回第一个。
5 * @example get_current_pressed_key.ino
6 * 获取当前按下的按键值若有多个按键按下则返回第一个。
7 */
8/**
9 * @~English
10 * @file get_current_pressed_key.ino
11 * @brief Example: Get the current pressed key value. If multiple keys are pressed, return the first one.
12 * @example get_current_pressed_key.ino
13 * Get the current pressed key value. If multiple keys are pressed, return the first one.
14 */
15#include <Wire.h>
16
17#include "matrix_keyboard.h"
18
19namespace {
20#if defined(ESP32)
21constexpr gpio_num_t kI2cPinSda = GPIO_NUM_21;
22constexpr gpio_num_t kI2cPinScl = GPIO_NUM_22;
23#endif
24
26} // namespace
27
28void setup() {
29 Serial.begin(115200);
30
31#if defined(ESP32)
32 Wire.begin(kI2cPinSda, kI2cPinScl);
33#else
34 Wire.begin();
35#endif
36
37 const auto result = g_matrix_keyboard.Initialize();
38
40 Serial.println(F("matrix keyboard initialization successful"));
41 } else {
42 Serial.print(F("Error: matrix keyboard initialization failed: "));
43 Serial.println(static_cast<uint32_t>(result));
44 while (true);
45 }
46}
47
48void loop() {
49 g_matrix_keyboard.Tick();
50
51 char key_value = g_matrix_keyboard.GetCurrentPressedKey();
52 if (key_value != '\0') {
53 Serial.print("Current pressed key: ");
54 Serial.println(key_value);
55 }
56}
MatrixKeyboard是用于矩阵键盘模块的驱动类。
static constexpr uint8_t kDefaultI2cAddress
默认I2C地址。