Button.ino 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Name: button.ino
  3. Created: 2018/9/21 14:06:15
  4. Author: sakabin
  5. */
  6. #include <M5Stack.h>
  7. // The setup() function runs once each time the micro-controller starts
  8. void setup() {
  9. // init lcd, serial, but don't init sd card
  10. M5.begin(true, false, true);
  11. /*
  12. Power chip connected to gpio21, gpio22, I2C device
  13. Set battery charging voltage and current
  14. If used battery, please call this function in your project
  15. */
  16. M5.Power.begin();
  17. M5.Lcd.clear(BLACK);
  18. M5.Lcd.setTextColor(YELLOW);
  19. M5.Lcd.setTextSize(2);
  20. M5.Lcd.setCursor(65, 10);
  21. M5.Lcd.println("Button example");
  22. M5.Lcd.setCursor(3, 35);
  23. M5.Lcd.println("Press button B for 700ms");
  24. M5.Lcd.println("to clear screen.");
  25. M5.Lcd.setTextColor(RED);
  26. }
  27. // Add the main program code into the continuous loop() function
  28. void loop() {
  29. // update button state
  30. M5.update();
  31. // if you want to use Releasefor("was released for"), use .wasReleasefor(int time) below
  32. if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
  33. M5.Lcd.print('A');
  34. } else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
  35. M5.Lcd.print('B');
  36. } else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
  37. M5.Lcd.print('C');
  38. } else if (M5.BtnB.wasReleasefor(700)) {
  39. M5.Lcd.clear(BLACK);
  40. M5.Lcd.setCursor(0, 0);
  41. }
  42. }