#include <LiquidCrystal.h>
#include <Stepper.h>
LiquidCrystal lcd(11, 10, 9, 8, 7, 6);
int yellow1LED = A0;
int yellow2LED = A1;
int yellow3LED = A2;
int greenLED = A3;
int gentleButton = 13;
int heavyButton = 12;
int offonButton = 5;
int buzzerPin = 4;
int washTemp = 0;
int buttonStateG = 0; //set the value as 0 to start the process
int buttonStateH = 0; //set the value as 0 to start the process
int buttonStateO = 0; //set the value as 0 to start the process
int lastButtonStateG = 0; //set the value as 0 to start the process
int lastButtonStateH = 0; //set the value as 0 to start the process
int lastButtonStateO = 0; //set the value as 0 to start the process
int washChoice = 0;
int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 3, 2, 1, 0);
//Melody code written by Chat GPT
const int NOTE_C4 = 262;
const int NOTE_D4 = 294;
const int NOTE_E4 = 330;
const int NOTE_F4 = 349;
const int NOTE_G4 = 392;
const int NOTE_A4 = 440;
const int NOTE_B4 = 494;
const int NOTE_C5 = 523;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(yellow1LED, OUTPUT);
pinMode(yellow2LED, OUTPUT);
pinMode(yellow3LED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(gentleButton, INPUT);
pinMode(heavyButton, INPUT);
pinMode(offonButton, INPUT);
lcd.begin(16,2);
}
int melody[] = { //ChatGPT
NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4,
NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_C4,
NOTE_G4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4,
NOTE_G4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4,
NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4,
NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_C4
};
int noteDurations[] = { //ChatGPT
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2
};
void buzzer() {//ChatGPT
for (int thisNote = 0; thisNote < sizeof(melody) / sizeof(melody[0]); thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(buzzerPin, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(buzzerPin);
}}
void WASH () {
lcd.print("Washing...");
digitalWrite(yellow1LED, HIGH);
myStepper.setSpeed(70);
for (int i = 0; i < 6; i++) {
myStepper.step(stepsPerRevolution); }
lcd.clear();
}
void RINSE () {
lcd.print("Rinsing...");
digitalWrite(yellow2LED, HIGH);
myStepper.setSpeed(70);
for (int i = 0; i < 4; i++) {
myStepper.step(-stepsPerRevolution); }
lcd.clear();
}
void SPIN () {
lcd.print("Spinning...");
digitalWrite(yellow3LED, HIGH);
myStepper.setSpeed(200);
for (int i = 0; i < 10; i++) {
myStepper.step(stepsPerRevolution); }
lcd.clear();
}
void heavyWASH () {
lcd.print("Washing...");
digitalWrite(yellow1LED, HIGH);
myStepper.setSpeed(70);
for (int i = 0; i < 15; i++) {
myStepper.step(stepsPerRevolution);}
lcd.clear();
}
void heavyRINSE () {
lcd.print("Rinsing...");
digitalWrite(yellow2LED, HIGH);
myStepper.setSpeed(70);
for (int i = 0; i < 7; i++) {
myStepper.step(-stepsPerRevolution); }
lcd.clear();
}
void heavySPIN () {
lcd.print("Spinning...");
digitalWrite(yellow3LED, HIGH);
myStepper.setSpeed(200);
for (int i = 0; i < 15; i++) {
myStepper.step(stepsPerRevolution); }
lcd.clear();
}
void GENTLE(){
// int buttonStateG = digitalRead(gentleButton); // DONT USE INT
buttonStateG = digitalRead(gentleButton); // Just use the line like this
if (buttonStateG != lastButtonStateG) { // Chech if a button has been pressed
if(buttonStateG == HIGH) {
lcd.clear(); // add this to clear the screen first
lcd.print("Gentle wash");
lcd.setCursor(0, 1);
lcd.print("selected");
delay(2000);
lcd.clear();
lcd.print("Gentle wash");
lcd.setCursor(0, 1);
lcd.print("starting...");
delay(1000);
lcd.clear();
lcd.print("3");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print("2");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print("1");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
lcd.clear();
WASH();
RINSE();
SPIN();
lcd.print("Gentle wash");
lcd.setCursor(0, 1);
lcd.print("completed!");
digitalWrite(yellow1LED, LOW);
digitalWrite(yellow2LED, LOW);
digitalWrite(yellow3LED, LOW);
digitalWrite(greenLED, HIGH);
buzzer();
digitalWrite(greenLED, LOW);
lcd.clear();
}
}
lastButtonStateG = buttonStateG; // Set the new value of ButtonG
}
void HEAVY(){
buttonStateH = digitalRead(heavyButton); // Just use the line like this
if (buttonStateH != lastButtonStateH) { // Chech if a button has been pressed
if(buttonStateH == HIGH){ // changed buttonState to buttonStateH
lcd.clear(); // add this to clear the screen first
lcd.print("Heavy wash");
lcd.setCursor(0, 1);
lcd.print("selected");
delay(2000);
lcd.clear();
lcd.print("Heavy wash");
lcd.setCursor(0, 1);
lcd.print("starting...");
delay(1000);
lcd.clear();
lcd.print("3");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print("2");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print("1");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
delay(250);
lcd.print(".");
lcd.clear();
heavyWASH();
heavyRINSE();
heavySPIN();
lcd.print("Heavy wash");
lcd.setCursor(0, 1);
lcd.print("completed!");
digitalWrite(yellow1LED, LOW);
digitalWrite(yellow2LED, LOW);
digitalWrite(yellow3LED, LOW);
digitalWrite(greenLED, HIGH);
buzzer();
digitalWrite(greenLED, LOW);
lcd.clear();
}
}
lastButtonStateH = buttonStateH; // Set the new value of ButtonH
}
void loop() {
buttonStateO = digitalRead(offonButton);
if (buttonStateO != lastButtonStateO) {
if (buttonStateO == HIGH) {
lcd.print("Power on");
delay(2500);
lcd.clear();
lcd.print("Select wash type");
}
while (buttonStateO == HIGH) {
GENTLE();
HEAVY();
}
}
lastButtonStateO = buttonStateO;
}