#include <LCD5110_Graph.h>
LCD5110 LCD(6,5,4,2,3);
extern unsigned char SmallFont[];
int datapin = 10;
int clockpin = 8;
int latchpin = 9;
byte data = 0;
int boton=7,level1=11,level2=12;
int inAgua=5,bomba2=3,dirMotor=1,motor=2,bomba1=4,detergente=6;
//////////////////////////////////////////////////////////////////
void setup(){
pinMode(datapin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(latchpin, OUTPUT);
LCD.InitLCD();
LCD.setFont(SmallFont);
pinMode(boton,INPUT);
chip(7,HIGH);chip(6,HIGH);chip(5,HIGH);chip(4,HIGH);chip(3,HIGH);chip(2,HIGH);chip(1,HIGH);
}
//////////////////////////////////////////////////////////////////
void loop(){
menu(selector());
}
//////////////////////////////////////////////////////////////////
void menu(int S){
delay(500);
switch(S){
case 0:
LCD.clrScr();
LCD.print("PROGRAMA",CENTER,18);
LCD.print("STANDARD",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
subMenuStandard();
}}
break;
default:
LCD.clrScr();
LCD.print( "PROGRAMA",CENTER,18);
LCD.print( "RAPIDO",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
subMenuRapid();}}
break;
}
}
//////////////////////////////////////////////////////////////////
int selector(){
int buff=0;
buff=analogRead(A1);
buff=constrain(map(buff,0,1023,0,9),0,9);
return buff;
}
//////////////////////////////////////////////////////////////////
void subMenuStandard(){
boolean exit=1;
while(exit){
switch (selector()){
case 0:
LCD.clrScr();
LCD.print( "START",CENTER,18);
LCD.print( "LLENAR AGUA",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
llenar(2);lava(40);desagua();llenar(0);lava(30);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 1:
LCD.clrScr();
LCD.print( "LAVADO",CENTER,18);
LCD.print( "40 min ...",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
lava(40);desagua();llenar(0);lava(30);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 2:
LCD.clrScr();
LCD.print( "DESAGUAR",CENTER,8);
LCD.print( "LLENAR Y",CENTER,18);
LCD.print( "LAVAR 30 min",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
desagua();llenar(0);lava(30);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 3:
LCD.clrScr();
LCD.print( "LAVAR 30 min",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
lava(30);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 4:
LCD.clrScr();
LCD.print( "PRE-CENTRIF",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 5:
LCD.clrScr();
LCD.print( "CENTRIFUGAR",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
desagua();centrifuga(5);finish();
}}
break;
default:
LCD.clrScr();
LCD.print( "ATRAS",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
exit=0;
break;}}
}}
}
//////////////////////////////////////////////////////////////////
void subMenuRapid(){
boolean exit=1;
while(exit){
switch (selector()){
case 0:
LCD.clrScr();
LCD.print( "START",CENTER,18);
LCD.print( "LLENAR AGUA",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
llenar(1);lava(30);desagua();llenar(0);lava(20);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 1:
LCD.clrScr();
LCD.print( "LAVADO",CENTER,18);
LCD.print( "30 min ...",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
lava(30);desagua();llenar(0);lava(20);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 2:
LCD.clrScr();
LCD.print( "DESAGUAR",CENTER,8);
LCD.print( "LLENAR Y",CENTER,18);
LCD.print( "LAVAR 20 min",CENTER,28);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
desagua();llenar(0);lava(20);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 3:
LCD.clrScr();
LCD.print( "LAVAR 20 min",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
lava(20);desagua();centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 4:
LCD.clrScr();
LCD.print( "PRE-CENTRIF",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
centrifuga(1);llenar(0);lava(5);desagua();centrifuga(5);finish();
}}
break;
case 5:
LCD.clrScr();
LCD.print( "CENTRIFUGAR",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
desagua();centrifuga(5);finish();
}}
break;
default:
LCD.clrScr();
LCD.print( "ATRAS",CENTER,20);
LCD.update();
if(!digitalRead(boton)){
delay(20);
if (!digitalRead(boton)){
delay(200);
exit=0;
break;}}
}}
}
//////////////////////////////////////////////////////////////////
void llenar(int level){
switch(level){
LCD.clrScr();
LCD.print( "LLENANDO",CENTER,18);
LCD.print( "AGUA....",CENTER,28);
LCD.update();
case 1:
while(!digitalRead(level1)){
chip(inAgua,LOW); // Start agua
}
chip(inAgua,HIGH); // Stop agua
lava(5);//5min
while(!digitalRead(level1)){
chip(inAgua,LOW); // Start agua
}
chip(inAgua,HIGH); // Stop agua
break;
case 2:
while(!digitalRead(level2)){
chip(inAgua,LOW); // Start agua
}
chip(inAgua,HIGH); // Stop agua
lava(5);//5min
while(!digitalRead(level2)){
chip(inAgua,LOW); // Start agua
}
chip(inAgua,HIGH); // Stop agua
break;
default:// //LLenar nivel 1 sin mas
while(digitalRead(level1)){
chip(inAgua,LOW); // Start agua
}
chip(inAgua,HIGH); // Stop agua
break;
LCD.clrScr();
LCD.update();
}}
//////////////////////////////////////////////////////////////////
void lava(int time){
LCD.clrScr();
LCD.print( "LAVANDO",CENTER,18);
LCD.print( ".....",CENTER,28);
LCD.update();
chip(bomba2,LOW); //Start bomba acccesoria
for(int i=0;i<time*6;i++){
chip(dirMotor,HIGH); //Cambio sentido motor
chip(motor,LOW); //Start motor
delay(4900);
chip(motor,HIGH); //Stop motor
delay(200);
chip(dirMotor,LOW); //Cambio sentido motor
chip(motor,LOW); //Start motor
delay(4900);
chip(motor,HIGH); //Stop motor
delay(200);
}
chip(bomba2,LOW); //Stop bomba acccesoria
LCD.clrScr();
LCD.update();
}
//////////////////////////////////////////////////////////////////
void desagua(){
LCD.clrScr();
LCD.print( "DESAGUANDO",CENTER,18);
LCD.print( ".....",CENTER,28);
LCD.update();
chip(bomba1,LOW); //Start bomba desague
delay(20000);
chip(bomba1,HIGH); //Stop bomba desague
LCD.clrScr();
LCD.update();
}
//////////////////////////////////////////////////////////////////
void centrifuga(int time){
LCD.clrScr();
LCD.print( "ESPERANDO",CENTER,18);
LCD.print( "CENTRIFUGADO",CENTER,28);
LCD.update();
while(digitalRead(boton)); //Espera que se pulse el boton
LCD.clrScr();
LCD.print( "CENTRIFUGANDO",CENTER,20);
LCD.update();
chip(motor,LOW); //Start motor
for(int i=0;i<time*60;i++){
chip(bomba1,LOW); //Start bomba desague
delay(700);
chip(bomba1,HIGH); //Stop bomba desague
delay(300);
}
LCD.clrScr();
LCD.update();
chip(motor,HIGH); //Stop motor
}
//////////////////////////////////////////////////////////////////
void finish(){
LCD.clrScr();
LCD.print( "FIN",CENTER,20);
LCD.update();
while(1);
}
//////////////////////////////////////////////////////////////////
void chip(int desiredPin, boolean desiredState)
{
bitWrite(data,desiredPin,desiredState);
shiftOut(datapin, clockpin, MSBFIRST, data);
digitalWrite(latchpin, HIGH);
digitalWrite(latchpin, LOW);
}
//////////////////////////////////////////////////////////////////
Comentarios
Publicar un comentario