//Learning Kit 2022 for M5Stack
//M5Stack_Gray_uln2003_stepper
#include <M5Stack.h>
#include <Stepper.h>
int i=0;
Stepper myStepper(2048,16,5,17,26);
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("Run stepper wiz ULN2003");
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);
myStepper.setSpeed(15);
}
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(i=1;i<=2;i++)
{
myStepper.step(2048);
}
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(i=1;i<=3;i++)
{
myStepper.step(512);
delay(50);
myStepper.step(-512);
}
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(i=1;i<=2;i++)
{
myStepper.step(-2048);
}
M5.Lcd.setCursor(0,180);
M5.Lcd.setTextColor(GREEN,BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.print("Press any key");
}
M5.update();
}
0 件のコメント:
コメントを投稿