ANGLE.ino 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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: Angle. 角度计
  10. * Date: 2021/8/9
  11. *******************************************************************************
  12. Description: Read the Angle of the angometer and convert it to digital display
  13. 读取角度计的角度,并转换为数字量显示
  14. */
  15. #include <M5Stack.h>
  16. int sensorPin =
  17. 36; // set the input pin for the potentiometer. 设置角度计的输入引脚
  18. int last_sensorValue =
  19. 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值
  20. int cur_sensorValue = 0; // Stores the value currently read by the sensor.
  21. // 存储传感器当前读取到的值
  22. void setup() {
  23. M5.begin(); // Init M5Stack. 初始化M5Stack
  24. M5.Power.begin(); // Init power 初始化电源模块
  25. pinMode(
  26. sensorPin,
  27. INPUT); // Sets the specified pin to input mode. 设置指定引脚为输入模式
  28. dacWrite(25, 0);
  29. M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字体大小为2
  30. M5.Lcd.print("the value of ANGLE: ");
  31. }
  32. void loop() {
  33. cur_sensorValue = analogRead(
  34. sensorPin); // read the value from the sensor. 读取当前传感器的值
  35. M5.Lcd.setCursor(0, 25); // Place the cursor at (0,25). 将光标固定在(0,25)
  36. if (abs(cur_sensorValue - last_sensorValue) > 10) { // debaunce
  37. M5.Lcd.fillRect(0, 25, 100, 25, BLACK);
  38. M5.Lcd.print(cur_sensorValue);
  39. last_sensorValue = cur_sensorValue;
  40. }
  41. delay(50);
  42. }