CardKB.ino 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. * Visit for more information: https://docs.m5stack.com/en/core/gray
  7. * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
  8. *
  9. * Describe: CardKB. 键盘
  10. * Date: 2021/8/11
  11. *******************************************************************************
  12. Please connect to Port A(22、21),Read the characters entered by CardKB Unit
  13. and display them on the screen. 请连接端口A(22、21),读取CardKB
  14. Unit输入的字符并显示在屏幕上。
  15. */
  16. #include <M5Stack.h>
  17. #define CARDKB_ADDR \
  18. 0x5F // Define the I2C address of CardKB. 定义CardKB的I2C地址
  19. void setup() {
  20. M5.begin(); // Init M5Stack. 初始化M5Stack
  21. M5.Power.begin(); // Init power 初始化电源模块
  22. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  23. M5.Lcd.printf("CardKB Test\n");
  24. M5.Lcd.printf(">>");
  25. }
  26. void loop() {
  27. Wire.requestFrom(
  28. CARDKB_ADDR,
  29. 1); // Request 1 byte from the slave device. 向从设备请求1字节
  30. while (
  31. Wire.available()) // If received data is detected. 如果检测到收到数据
  32. {
  33. char c = Wire.read(); // Store the received data. 将接收到的数据存储
  34. if (c != 0) {
  35. M5.Lcd.printf("%c", c);
  36. Serial.println(c, HEX);
  37. }
  38. }
  39. }