/* 
* Tittle: Washing Machine Control Panel
* Author: Amos Mulholland
* Date: March - June 2024
* Purpose: to create a functioning washing machine control pannel
* Red Button = Power
* Green Button = Gentle Wash
* Blue Button = Heavy Wash
*/ 

// libraries
#include <LiquidCrystal.h>

#include <pitches.h>

#include <Stepper.h>

//Ints
const int gentle_wash = 6;
const int power_button = 5;
const int heavy_wash = 4;
const int OrangeLed_PIN = A3;
const int RedLed1_PIN = A2;
const int RedLed2_PIN = A1;
const int GreenLed_PIN = A0;
const int BUZZER_PIN = 13;
const int stepsPerRevolution = 200; 
int buttonState = 0;        
int lastButtonState = 0;  
int buttonPin = 5;          
Stepper myStepper(stepsPerRevolution, 3, 2, 1, 0);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

//Setup
void setup() {
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(13, OUTPUT);
}

//LED method
void blinkLED (int pin, int duration) {
  digitalWrite(pin, HIGH);
delay(duration);
digitalWrite(pin, LOW);
}

//Start of CHAT GPT
// Define the notes of "Ode to Joy" melody
int melody[] = {
  NOTE_E4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C4,
  NOTE_C4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4,
  NOTE_E4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C4,
  NOTE_C4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C4
};

// Define the note durations
int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4, 4,
  4, 4, 4, 4, 4, 2,
  4, 4, 4, 4, 4, 4, 4, 4, 4,
  4, 4, 4, 4, 4, 2
};


// Function to play the "Ode to Joy" melody on the buzzer 
void BUZZER() {
  for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
    int noteDuration = 1000 / noteDurations[i];
    tone(BUZZER_PIN, melody[i], noteDuration);

    // Pause between notes
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // Stop the tone playing
    noTone(BUZZER_PIN);
  }
}
//End of CHAT GPT

//Different parts of the wash cycles (Heavy & Gentle) 
void WASH () {
myStepper.setSpeed(70);
 for (int i = 0; i < 6; i++) {
  myStepper.step(stepsPerRevolution); }
}

void HEAVY () {
  myStepper.setSpeed(70);
 for (int i = 0; i < 15; i++) {
  myStepper.step(stepsPerRevolution);}
}

void RINSE () {
  myStepper.setSpeed(70);
 for (int i = 0; i < 4; i++) {
  myStepper.step(-stepsPerRevolution); }
}

void HEAVY_RINSE () {
  myStepper.setSpeed(70);
 for (int i = 0; i < 7; i++) {
  myStepper.step(-stepsPerRevolution); }
}

void SPIN () {
myStepper.setSpeed(200);
 for (int i = 0; i < 10; i++) {
  myStepper.step(stepsPerRevolution); }
}

void HEAVY_SPIN () {
myStepper.setSpeed(200);
 for (int i = 0; i < 15; i++) {
  myStepper.step(stepsPerRevolution); }
}

//Gentle wash (Green Button)
void GENTLE () {
int buttonState = digitalRead(gentle_wash);
int gentle_wash = 6;

if(buttonState == HIGH){
  digitalWrite(A3, HIGH);
  lcd.blink();
  lcd.noBlink();
  lcd.print("Gentle Wash Selected");
  delay(3000);
  lcd.clear();    
  lcd.print("Gentle Wash starting");
  delay(3000);
  lcd.clear();    
  lcd.print("3...");
  delay(1000);
  lcd.clear();    
  lcd.print("2...");
  delay(1000);
  lcd.clear();    
  lcd.print("1...");
  delay(1000);
  lcd.clear();    
  digitalWrite(A3, LOW);
  digitalWrite(A2, HIGH);
  lcd.print("Washing"); 
  WASH () ;
  lcd.clear();   
  delay(1000);
  lcd.print("Rinsing"); 
  RINSE ();
  digitalWrite(A2, LOW);
  lcd.clear();   
  delay(1000);
  digitalWrite(A1, HIGH);
  lcd.print("Spinning"); 
  SPIN ();
  digitalWrite(A1, LOW);
  lcd.clear();   
  delay(2000);
  digitalWrite(A0, HIGH);
  lcd.print("Gentle Wash Finished"); 
  BUZZER ();
  delay(60000);
  digitalWrite(A0, LOW);
  }
}

//Heavy Duty Wash (Blue Button)
void HEAVY_DUTY () {
int buttonState = digitalRead(heavy_wash);
int heavy_wash = 4;

if(buttonState == HIGH){
  digitalWrite(A3, HIGH);
  lcd.blink();
  lcd.noBlink();
  lcd.print("Heavy Wash Selected");
  delay(3000);
  lcd.clear();    
  lcd.print("Heavy Wash Starting");
  delay(3000);
  lcd.clear();    
  lcd.print("3...");
  delay(1000);
  lcd.clear();    
  lcd.print("2...");
  delay(1000);
  lcd.clear();    
  lcd.print("1...");
  delay(1000);
  lcd.clear();    
  digitalWrite(A3, LOW);
  digitalWrite(A2, HIGH);
  lcd.print("Heavy Duty Washing"); 
  HEAVY () ;
  lcd.clear();   
  delay(1000);
  lcd.print("Rinsing"); 
  HEAVY_RINSE ();
  digitalWrite(A2, LOW);
  lcd.clear();   
  delay(1000);
  digitalWrite(A1, HIGH);
  lcd.print("Spinning"); 
  HEAVY_SPIN ();
  digitalWrite(A1, LOW);
  lcd.clear();   
  delay(2000);
  digitalWrite(A0, HIGH);
  lcd.print("Heavy Wash Finished"); 
  BUZZER ();
  delay(60000);
  digitalWrite(A0, LOW);
  }
}

//Running the program (Red Button)
void loop(){
buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState) { 

    if (buttonState == HIGH) {

      lcd.print("POWER ON"); 
      delay(3000);
      lcd.clear(); 
      GENTLE();
      HEAVY_DUTY();

    }
  }

  lastButtonState = buttonState;

}
$abcdeabcde151015202530354045505560fghijfghij