ANGLE.ino 889 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Description: Read ANGLE Unit input analog quantity, and convert to 12-bit digital quantity for display
  3. */
  4. #include <M5Stack.h>
  5. // select the input pin for the potentiometer
  6. int sensorPin = 36;
  7. // last variable to store the value coming from the sensor
  8. int last_sensorValue = 100;
  9. // current variable to store the value coming from the sensor
  10. int cur_sensorValue = 0;
  11. void setup() {
  12. M5.begin();
  13. M5.Power.begin();
  14. pinMode(sensorPin, INPUT);
  15. dacWrite(25, 0);
  16. M5.Lcd.setTextSize(2);
  17. M5.Lcd.setCursor(0, 0);
  18. M5.Lcd.print("the value of ANGLE: ");
  19. }
  20. void loop() {
  21. // read the value from the sensor:
  22. cur_sensorValue = analogRead(sensorPin);
  23. M5.Lcd.setCursor(0, 25);
  24. if(abs(cur_sensorValue - last_sensorValue) > 10){//debaunce
  25. M5.Lcd.fillRect(0, 25, 100, 25, BLACK);
  26. M5.Lcd.print(cur_sensorValue);
  27. last_sensorValue = cur_sensorValue;
  28. }
  29. delay(50);
  30. }