2020-04-29 22:29:41 -04:00
|
|
|
/*
|
2025-01-14 10:53:33 +08:00
|
|
|
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* @Hardwares: M5Core + Unit CardKB
|
|
|
|
|
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
|
|
|
|
|
* @Dependent Library:
|
|
|
|
|
* M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
|
|
|
|
|
*/
|
2019-05-29 09:41:49 +08:00
|
|
|
|
2021-08-11 14:38:13 +08:00
|
|
|
#include <M5Stack.h>
|
2019-05-29 09:41:49 +08:00
|
|
|
|
2025-01-14 10:53:33 +08:00
|
|
|
#define CARDKB_ADDR (0x5F) // Define the I2C address of CardKB. 定义CardKB的I2C地址
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
2022-07-04 14:52:25 +08:00
|
|
|
M5.begin(); // Init M5Stack. 初始化M5Stack
|
|
|
|
|
M5.Power.begin(); // Init power 初始化电源模块
|
|
|
|
|
M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
|
|
|
|
|
M5.Lcd.printf("CardKB Test\n");
|
|
|
|
|
M5.Lcd.printf(">>");
|
2019-05-29 09:41:49 +08:00
|
|
|
}
|
2025-01-14 10:53:33 +08:00
|
|
|
void loop()
|
|
|
|
|
{
|
|
|
|
|
Wire.requestFrom(CARDKB_ADDR, 1); // Request 1 byte from the slave device. 向从设备请求1字节
|
|
|
|
|
while (Wire.available()) // If received data is detected. 如果检测到收到数据
|
2019-05-29 09:41:49 +08:00
|
|
|
{
|
2022-07-04 14:52:25 +08:00
|
|
|
char c = Wire.read(); // Store the received data. 将接收到的数据存储
|
|
|
|
|
if (c != 0) {
|
|
|
|
|
M5.Lcd.printf("%c", c);
|
|
|
|
|
Serial.println(c, HEX);
|
|
|
|
|
}
|
2019-05-29 09:41:49 +08:00
|
|
|
}
|
|
|
|
|
}
|