// Include the Stepper library
#include <Stepper.h>
#include <ezButton.h>
#include <LiquidCrystal.h>
// Define the number of steps per revolution
const int stepsPerRevolution = 200;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
// Define the motor pins
#define motorPin1 2
#define motorPin2 3
#define motorPin3 4
#define motorPin4 5
ezButton button (A0);
#define LED A1
int stepperPower = 1;
// Initialize the stepper motor object
// Since it's a unipolar motor, use the Stepper library
Stepper myStepper(stepsPerRevolution, motorPin1, motorPin2, motorPin3, motorPin4);
void setup() {
// Set the speed of the motor (in RPM)
myStepper.setSpeed(60);
pinMode (LED, OUTPUT);
lcd.begin(16, 2);
}
void LCD(){
lcd.blink(); //Displays the blinking LCD cursor
delay(500); //wait 4 seconds
lcd.noBlink(); // Turns off the blinking LCD cursor
lcd.print("Washing Machine"); //prints Hello World! on the LCD
delay(500);
lcd.setCursor(0,1); //starts text 3 blocks in on the 2nd line
lcd.print("On!");
delay(1000);
lcd.clear(); //clears the screen
}
void stepper(){
if(stepperPower == 1){
for (int x = 0; x < 5; x++) {
// Step forward 2 revolutions (clockwise)
for (int i = 0; i < stepsPerRevolution; i++) {
myStepper.step(1);
delay(5); // Small delay to control speed
}
delay(500); // Wait for one second
// Step backward 2 revolutions (counter-clockwise)
for (int i = 0; i < stepsPerRevolution; i++) {
myStepper.step(-1);
delay(5); // Small delay to control speed
}
delay(500); // Wait for one second before repeating the loop
}
stepperPower = 0;
}
}
void buton(){
button.loop();
if(button.isPressed()){
LCD();
digitalWrite(LED, HIGH);
stepper();
digitalWrite(LED, LOW);
}
}
void loop() {
buton();
}