pir.ino 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: PIR. 人体红外
  10. * Date: 2021/8/11
  11. *******************************************************************************
  12. Please connect to Port B(26、36),Human body detection using PIR Unit.
  13. 请连接端口B(26、36),使用PIR Unit进行人体检测。
  14. */
  15. #include <M5Stack.h>
  16. void setup() {
  17. M5.begin(); // Init M5Stack. 初始化M5Stack
  18. M5.Power.begin(); // Init power 初始化电源模块
  19. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  20. M5.Lcd.println("PIR example");
  21. M5.Lcd.setCursor(0,
  22. 25); // Position the cursor at (0,25). 将光标固定在(0,25)
  23. M5.Lcd.println("Status: \nValue: ");
  24. pinMode(36, INPUT); // Set pin 36 to input mode. 设置36号引脚为输入模式
  25. }
  26. void loop() {
  27. M5.Lcd.fillRect(90, 25, 180, 50,
  28. BLACK); // Draw a black rectangle 180 by 50 at (90,25).
  29. // 在(90,25)处画一个宽180高50的黑的矩形
  30. if (digitalRead(36) ==
  31. 1) { // If pin 36 reads a value of 1. 如果36号引脚的读取到的值为1
  32. M5.Lcd.setCursor(95, 25);
  33. M5.Lcd.print("Sensing");
  34. M5.Lcd.setCursor(95, 45);
  35. M5.Lcd.print("1");
  36. } else {
  37. M5.Lcd.setCursor(95, 25);
  38. M5.Lcd.print("Not Sensed");
  39. M5.Lcd.setCursor(95, 45);
  40. M5.Lcd.print("0");
  41. }
  42. delay(500);
  43. }