/*
*Title: Wishiwashi machine
*Author: Ostara Sheppard
*Date: 01/05/2024
*Version: v1.0
*Purpose: the purpose of this code is to run a spin cycle on a washing machine
*/
#include <Stepper.h>
//declare variables here!
int ledPin = 6; // pin for the LED signal
int buttonPin = 5; // pin for the button signal
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 1, 2, 3, 4);
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 11, 10, 9, 8, 7);
//const int redled = 13; //redled is connected to digital pin 13
//const int greybtn = 13; //greybtn is connected to digital pin 13
//Servo myServo; //declare a servo object
void setup() {
// put your setup code here, to run once:
//pinMode(12, OUTPUT); //set pin 12 as an output for bluebtn
//pinMode(11, OUTPUT); //set pin 11 as an output for blueled
myStepper.setSpeed(60);
lcd.begin(16, 2); //display of 16 letters and 2 rows
// you can now interact with the LCD
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void Poweron () { //create a function called Poweron
delay(4000); //wait 2 seconds
lcd.noBlink(); // Turns off the blinking LCD cursor
lcd.clear();
lcd.print("Starting"); //prints Powered On on the LCD
delay(2000);
lcd.clear();
lcd.setCursor(3,1); //starts text 3 blocks in on the 2nd line
lcd.print("Select cycles");
delay(2000);
lcd.clear(); //clears the screen
}
void rinsecycle () { //create a function called rinsecycle
for (int i = 0; i < 3; i++) {
lcd.clear();
lcd.print("Rinsing"); //prints Powered On on the LCD
myStepper.step(stepsPerRevolution);
delay(500); // Delay between steps, adjust as needed
}
}
void spincycle () { //create a function called spincycle
for (int i = 0; i < 3; i++) {
lcd.clear();
lcd.print("Spinning"); //prints Powered On on the LCD
myStepper.step(stepsPerRevolution);}
delay(50); // Delay between steps, adjust as needed
}
void washcycle () { //create a function called washcycle
for (int i = 0; i < 3; i++) {
// Step the motor 1 revolution clockwise
lcd.clear();
lcd.print("Washing"); //prints Powered On on the LCD
myStepper.step(stepsPerRevolution);
delay(500); // Delay between steps, adjust as needed
// Anticlockwise rotation
// Step the motor 1 revolution anticlockwise
myStepper.step(-stepsPerRevolution);
delay(500); // Delay between steps, adjust as needed
}
}
void WashingCycle() {
washcycle();
rinsecycle();
spincycle();
lcd.clear();
lcd.print("Finished");
lcd.clear();
lcd.print("Goodbye");
lcd.clear();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) { // != is Arduino code for Not Equal to
if (buttonState == HIGH) { // == Checks if the value of two operands is equal or not, if yes then condition becomes true.
digitalWrite(ledPin, !digitalRead(ledPin)); // toggle the LED
lcd.print("Power On");
Poweron();
WashingCycle();
}
}
lastButtonState = buttonState;
}