LIMIT.ino 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. *
  7. * Visit for more information: https://docs.m5stack.com/zh_CN/products
  8. * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
  9. *
  10. * Describe: Limit.
  11. * Date: 2022/6/1
  12. *******************************************************************************
  13. */
  14. #include <M5Stack.h>
  15. #define KEY_PIN 36 // Define Limit Pin. 定义Limit连接引脚
  16. void setup() {
  17. M5.begin(); // Init M5Stack 初始化M5Stack
  18. M5.Lcd.setTextSize(4);
  19. M5.Lcd.print(("\n UNIT-LIMIT\n Example"));
  20. pinMode(KEY_PIN, INPUT_PULLUP); // Init Limit pin. 初始化Limit引脚.
  21. }
  22. void loop() {
  23. if (!digitalRead(KEY_PIN)) { // If Limit was hit. 如果触碰了Limit.
  24. M5.Lcd.setCursor(0, 130);
  25. M5.Lcd.print((" Hit limit!"));
  26. } else {
  27. M5.Lcd.setCursor(0, 130);
  28. M5.Lcd.println((" "));
  29. }
  30. delay(100);
  31. }