Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to create a washing machine that performs these fuctions: Economy Washes dishes in cold water for 5 minutes and then runs the

I am trying to create a washing machine that performs these fuctions:

Economy

Washes dishes in cold water for 5 minutes and then runs the dryer for 2 minutes. (To speed up testing, we will use seconds as the unit of time rather than minutes. Anyplace that indicates time as X minutes you should actually use X seconds)

Deluxe

Washes dishes in hot water for 7 minutes and then runs the dryer for 7 minutes.

Super Deluxe

Washes dishes in hot water for 7 minutes, then in medium water (both hot and cold) for 7 minutes, then finally runs the dryer for 7 minutes.

S&S would like to give users the flexibility to mix and match wash and dry cycles by adjusting the control knob in the middle of the current cycle. In particular theyd like:

If the knob is changed to Economy during a Deluxe or Super Deluxe wash, it should proceed to the Economy drying process.

If the knob is changed to either Deluxe or Super Deluxe during an Economy wash cycle it should proceed to the same drying behavior as Deluxe or Super Deluxe.

Reminder: The Super Deluxe wash cycle should never be cut short. It should always wash with hot water for 7 minutes, then in medium water (both hot and cold) for 7 minutes (even if the knob is turned to Economy half way though).

Also keep in mind that the door to the washer should be locked whenever its running.

Hot water on

Cold water on

Dryer on

Locked (On means the door is locked)

Using an actual machine for your testing would be awkward, so you should simulate the outputs by using LEDs. Use:

Red for hot water

Green for cold water

Yellow for the Dryer

The Blue LED thats already on Pin 13 for Locked

the potentiometer controls which cycle to perform.

This is my code:

const int POT_PIN = 0;

const int BUTTON_PIN = 3;

const int HOT_PIN = 11; //RED

const int COLD_PIN = 12; //GREEN

const int DRY_PIN = 10; //YELLOW

const int LOCK_PIN = LED_BUILTIN; //BLUE

int potVal = 0;

int potState = 0;

int buttonState = 0;

enum State{

idle,

econWash,

econDry,

delWash,

delDry,

superDelWash,

};

State washCycle(State state);

State state;

void setup() {

pinMode(HOT_PIN, OUTPUT);

pinMode(COLD_PIN, OUTPUT);

pinMode(DRY_PIN, OUTPUT);

pinMode(LOCK_PIN, OUTPUT);

pinMode(POT_PIN, INPUT);

pinMode(BUTTON_PIN, INPUT);

state = idle;

Serial.begin(9600);

}

void loop() {

buttonState = digitalRead(BUTTON_PIN);

potVal = analogRead(POT_PIN);

Serial.println(buttonState);

if (potVal < 341){

potState = 1;

}

else if (potVal < 682){

potState = 2;

}

else{

potState = 3;

}

if (buttonState == 1){

if (potState == 1){

state = washCycle(econWash);

}

else if (potState == 2) {

state = washCycle(delWash);

}

else{

state = washCycle(superDelWash);

}

}

}

State washCycle (State state) {

switch(state) {

case idle :

digitalWrite(HOT_PIN , 0);

digitalWrite(COLD_PIN , 0);

digitalWrite(DRY_PIN , 0);

digitalWrite(LOCK_PIN , 0);

return idle;

case econWash :

digitalWrite(LOCK_PIN , 1);

digitalWrite(COLD_PIN , 1);

delay(5000);

digitalWrite(COLD_PIN , 0);

if (checkSwitch()){

return delDry;

}

else{

return econDry;

}

case delWash :

digitalWrite(HOT_PIN , 1);

digitalWrite(LOCK_PIN , 1);

delay(7000);

digitalWrite(HOT_PIN , 0);

if (checkSwitch()){

return delDry;

}

else{

return econDry;

}

case superDelWash :

digitalWrite(LOCK_PIN , 1);

digitalWrite(HOT_PIN, 1);

delay(7000);

digitalWrite(COLD_PIN, 1);

delay(7000);

digitalWrite(COLD_PIN, 0);

digitalWrite(HOT_PIN, 0);

if (checkSwitch()){

return delDry;

}

else{

return econDry;

}

case delDry :

digitalWrite(DRY_PIN , 1);

delay(7000);

return idle;

case econDry :

digitalWrite(DRY_PIN , 1);

delay(2000);

return idle;

}

}

bool checkSwitch() {

potVal = analogRead(POT_PIN);

if (potVal >= 341){

return true;

}

else{

return false;

}

}

However, it doesnt work. I think the button may be this issue. Can somoene help with this?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions