HALL.ino 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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: Hall. 霍尔传感器
  10. * Date: 2021/8/18
  11. *******************************************************************************
  12. Please connect to Port B,Displays a string on the screen.
  13. 请连接端口B,在屏幕上显示字符串。
  14. Low-level signal can be generated when the magnet S pole is close to the front
  15. of the sensor 当磁体S极靠近传感器前端时,会产生低电平信号 OR the N pole is close
  16. to the back, and the internal LED indicator will light up, the screen wiil
  17. display 0. 或N极靠近背面,内部LED指示灯亮起,屏幕显示0。
  18. */
  19. #include <M5Stack.h>
  20. #define HALL 36
  21. void setup() {
  22. M5.begin(); // Init M5Stack. 初始化M5Stack
  23. M5.Power.begin(); // Init power 初始化电源模块
  24. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  25. M5.Lcd.print(" HALL Sensor");
  26. pinMode(HALL,
  27. INPUT); // Set the pins to which the Hall sensor is connected to
  28. // the input mode. 将霍尔传感器所连接的引脚设置为输入模式
  29. }
  30. void loop() {
  31. bool status = digitalRead(HALL);
  32. M5.Lcd.setCursor(20, 80);
  33. M5.Lcd.printf("Hall status : %d", status);
  34. }