Created
March 11, 2021 04:11
-
-
Save Shinichi-Ohki/88b957882a40175f24409cbd1220a9c5 to your computer and use it in GitHub Desktop.
M5Stack Core2 vibration test sketch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5Core2.h> | |
void vibration(int t) { | |
M5.Axp.SetLDOEnable(3, true); | |
delay(t); | |
M5.Axp.SetLDOEnable(3, false); | |
} | |
void setup() { | |
M5.begin(true, true, true, true); | |
M5.Lcd.fillScreen(WHITE); | |
M5.Lcd.setTextColor(BLACK); | |
M5.Lcd.setTextSize(3); | |
M5.Lcd.setRotation(2); | |
M5.Lcd.setCursor(150, 42); | |
M5.Lcd.printf("500ms"); | |
M5.Lcd.setCursor(150, 150); | |
M5.Lcd.printf("200ms"); | |
M5.Lcd.setCursor(60, 255); | |
M5.Lcd.printf("while push"); | |
delay(100); | |
} | |
bool button = false; | |
void loop() { | |
TouchPoint_t pos = M5.Touch.getPressPoint(); | |
if (pos.x >= 0) { | |
if (pos.y > 240 && pos.x < 109) { | |
M5.Axp.SetLDOEnable(3, true); | |
Serial.println("button 1"); | |
} else if (pos.y > 240 && pos.x >= 110 && pos.x < 219) { | |
if (!button) vibration(200); | |
button = true; | |
Serial.println("button 2"); | |
} else if (pos.y > 240 && pos.x >= 220) { | |
if (!button) vibration(500); | |
button = true; | |
Serial.println("button 3"); | |
} | |
} else { | |
M5.Axp.SetLDOEnable(3, false); | |
button = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment