//Learning Kit 2022 for M5Stack
//M5Stack_Gray_runservo
#include <M5Stack.h>
#include <ESP32Servo.h>
Servo myservo;
int servoPin=16;
int posVal=0;
int cnt=0;
void OpenScreen()
{
M5.Lcd.setCursor(0,0);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.print("Welcome to M5Stack Gray");
M5.Lcd.setCursor(0,20);
M5.Lcd.print("Coded by Kim Grossa");
M5.Lcd.setCursor(0,40);
M5.Lcd.print("Servo Sweep");
M5.Lcd.setCursor(0,70);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.setTextSize(3);
M5.Lcd.print("ButtonA Reverse");
M5.Lcd.setCursor(0,100);
M5.Lcd.print("ButtonB Wiper");
M5.Lcd.setCursor(0,130);
M5.Lcd.print("ButtonC Forward");
}
void setup()
{
M5.begin();
M5.Power.begin();
M5.Lcd.setBrightness(200);
myservo.setPeriodHertz(50);
myservo.attach(servoPin,500,2500);
}
void loop()
{
boolean aBtn = M5.BtnA.wasPressed();
boolean bBtn = M5.BtnB.wasPressed();
boolean cBtn = M5.BtnC.wasPressed();
OpenScreen();
if(aBtn)
{
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Reverse........");
for (cnt=0;cnt<=3;cnt +=1)
{
for (posVal = 0; posVal <= 180; posVal += 1)
{
myservo.write(posVal);
delay(15);
}
}
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Press any key..");
}
if(bBtn)
{
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Wiper.........");
for (cnt=0;cnt<=5;cnt +=1)
{
for (posVal = 45; posVal <= 135; posVal += 10)
{
myservo.write(posVal);
delay(15);
}
for (posVal = 135; posVal >= 45; posVal -= 10)
{
myservo.write(posVal);
delay(15);
}
}
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Press any key");
}
if(cBtn)
{
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Forward......");
for (cnt=0;cnt<=3;cnt +=1)
{
for (posVal = 180; posVal >= 0; posVal -= 1)
{
myservo.write(posVal);
delay(15);
}
}
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Press any key..");
}
M5.update();
}
0 件のコメント:
コメントを投稿