CardKB.ino 751 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Description: Read the characters entered by CardKB Unit and display them on the screen.
  3. */
  4. #include <Wire.h>
  5. #include <M5Stack.h>
  6. #define CARDKB_ADDR 0x5F
  7. void setup()
  8. {
  9. M5.begin();
  10. M5.Power.begin();
  11. Serial.begin(115200);
  12. Wire.begin();
  13. pinMode(5, INPUT);
  14. digitalWrite(5, HIGH);
  15. M5.Lcd.fillScreen(BLACK);
  16. M5.Lcd.setCursor(1, 10);
  17. M5.Lcd.setTextColor(YELLOW);
  18. M5.Lcd.setTextSize(2);
  19. M5.Lcd.printf("IIC Address: 0x5F\n");
  20. M5.Lcd.printf(">>");
  21. }
  22. void loop()
  23. {
  24. Wire.requestFrom(CARDKB_ADDR, 1);
  25. while(Wire.available())
  26. {
  27. char c = Wire.read(); // receive a byte as characterif
  28. if (c != 0)
  29. {
  30. M5.Lcd.printf("%c", c);
  31. Serial.println(c, HEX);
  32. // M5.Speaker.beep();
  33. }
  34. }
  35. // delay(10);
  36. }