Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-os KeypadLib TextLCD
electrocoagulador_final.cpp
- Committer:
- afsaavedram
- Date:
- 2019-03-02
- Revision:
- 3:a4994da37d1f
- Parent:
- 2:4b27d3d7341a
- Child:
- 4:2636fe1c6527
File content as of revision 3:a4994da37d1f:
#include "mbed.h"
#include "keypad.h"
#include "TextLCD.h"
#include "stdlib.h"
/*******************ELECTROVALVULAS********************/
DigitalOut E_1(D8,0); //Control de electrovalvula 1
DigitalOut E_2(D9,0); //Control de electrovalvula 2
DigitalOut E_3(D10,0); //Control de electrovalvula 3
DigitalOut E_4(D12,0); //Control de electrovalvula 4
AnalogIn sensor_nivel(A0); //Sensor nivel tanque 1
/*****************************************************/
/*******************INTERRUPCIONES********************/
InterruptIn button(USER_BUTTON);
Timeout t_1;
Timeout t_2;
Timeout t_3;
Timeout t_4;
//tiempos de usuario
int temp_user_1=0; //tiempo tope de electrocoagulacion
int temp_user_2=0; //tiempo tope de reposo de la vinaza
int temp_user_3=0; //tiempo tope de vaciado del agua en el tanque 2
int temp_user_4=0; //tiempo tope de vaciado de residuos en el tanque 2
/********************TECLADO Y LCD***********************/
// rs, e,d4,d5,d6,d7
TextLCD lcd(PC_8,PC_9,PC_10,PC_11,PC_12,PD_2);
Keypad keypad(D3, D2, D1, D0, D7, D6, D5, D4);
float num=0;
char cadena[3]= {' ',' ',' '};
int llena=0; //verificar que la entrada es de 3 numeros
/*********************FUNCIONES**************************/
void stop() //STOP
{
while(1) {
lcd.cls();
lcd.printf(" STOP!");
lcd.locate(0,1);
lcd.printf(" PLEASE RESET");
wait_ms(150);
}
}
void electro_1()
{
E_1=!E_1;
}
void electro_2()
{
E_2=!E_2;
}
void electro_3()
{
E_3=!E_3;
}
void electro_4()
{
E_4=!E_4;
}
/***********************MAIN***************************/
int main()
{
button.rise(&stop);
keypad.enablePullUp();
wait(1);
lcd.locate(0,0);
lcd.printf(" Control para\n");
lcd.locate(0,1);
lcd.printf("electrocoagular\n");
wait(1.5);
lcd.cls();
while(1) {
ini_1:
lcd.cls();
lcd.locate(0,0);
lcd.printf("t_1=%d",temp_user_1);
lcd.locate(8,0);
lcd.printf("t_2=%d",temp_user_2);
lcd.locate(0,1);
lcd.printf("t_3=%d",temp_user_3);
lcd.locate(8,1);
lcd.printf("t_4=%d",temp_user_4);
wait_ms(100);
char key = keypad.getKey();
//if(key=='A') {
//lcd.cls();
//lcd.locate(0,0);
//lcd.printf("%c",key);
//wait(3);
// lcd.printf("t_1=%f",temp_user_1);
if(key=='1') {
temp_user_1=temp_user_1+10;
if(temp_user_1<00) {
temp_user_1=00;
}
wait_ms(150);
}
if(key=='2') {
temp_user_1=temp_user_1-1;
if(temp_user_1<00) {
temp_user_1=00;
}
wait_ms(150);
}
if(key=='3') {
temp_user_2=temp_user_2+10;
if(temp_user_2<00) {
temp_user_2=00;
}
wait_ms(150);
}
if(key=='A') {
temp_user_2=temp_user_2-1;
if(temp_user_2<00) {
temp_user_2=00;
}
wait_ms(150);
}
if(key=='4') {
temp_user_3=temp_user_3+10;
if(temp_user_3<00) {
temp_user_3=00;
}
wait_ms(150);
}
if(key=='5') {
temp_user_3=temp_user_3-1;
if(temp_user_3<00) {
temp_user_3=00;
}
wait_ms(150);
}
if(key=='6') {
temp_user_4=temp_user_4+10;
if(temp_user_4<00) {
temp_user_4=00;
}
wait_ms(150);
}
if(key=='B') {
temp_user_4=temp_user_4-1;
if(temp_user_4<00) {
temp_user_4=00;
}
wait_ms(150);
}
/***********************COMIENZA CONTROL***********************/
if(key=='D' && temp_user_1!=0) {
t_1.attach(&electro_1,temp_user_1);
} else if (key=='D' && temp_user_1==0) {
lcd.cls();
lcd.printf(" t_1 empty");
wait(1.5);
key='\0';
goto ini_1;
}
/*
if(key=='A'){
while(llena<=2){
if(llena<3){
cadena[llena]=keypad.getKey();
temp_user_1=strtod(cadena,NULL);
llena++;
switch(llena){
case 0:
if(llena==0 && keypad.getKey()!= '\0'){
cadena[llena]=keypad.getKey();
llena=llena +1;
break;
}
case 1:
if(llena==1 && keypad.getKey()!= '\0'){
cadena[llena]=keypad.getKey();
llena=llena+1;
break;
}
case 2:
if(llena==2 && keypad.getKey()!= '\0'){
cadena[llena]=keypad.getKey();
llena=llena+1;
break;}
default:
break;
}*/
//lcd.cls();
//temp_user_1=strtod(cadena,NULL);
//lcd.locate(0,0);
//lcd.printf("t_1=%f",temp_user_1);
}//termina while de main
}//termina main