control de temperatura por medio de un sensor LM35
Dependencies: Keypad TextLCD mbed
Fork of control_onoff by
main.cpp
- Committer:
- Luis_San
- Date:
- 2017-11-16
- Revision:
- 1:b5269aa460c0
- Parent:
- 0:e007beba2811
File content as of revision 1:b5269aa460c0:
#include "mbed.h" #include "TextLCD.h" #include "Keypad.h" Serial rs232(USBTX, USBRX); AnalogIn AnalogPin(PTB0); DigitalOut pinOut(PTB1); TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7, RW=GND Keypad keypad(PTB11,PTB10,PTB9,PTB8,PTE5,PTE4,PTE3,PTE2); // c1, c2, c3, c4, f1, f2, f3, f4 char key; int released=1,unidades,decenas,centenas; float setpoint,valor_adc; void read_kpad() { key=keypad.ReadKey(); if(key=='\0') released=1; if((key!='\0') && (released==1)) { released=0; } } void setup_pyrom() { int i=0; lcd.cls(); lcd.locate(1,1); lcd.printf("SETUP..."); rs232.printf("SETUP..."); wait(1); lcd.cls(); while(i<=2){ read_kpad(); wait(0.5); if(key!='\0'){ if(i==0){centenas=key-48;lcd.locate(1,1);lcd.printf("%c",key);if(centenas>1){centenas=1;}} if(i==1){decenas=key-48;lcd.locate(2,1);lcd.printf("%c",key);} if(i==2){unidades=key-48;lcd.locate(3,1);lcd.printf("%c",key);} ++i;} } wait(0.25); setpoint=unidades+10.0*decenas+100.0*centenas; lcd.cls(); lcd.locate(1,1); lcd.printf("SP: %fdegC ",setpoint); rs232.printf("SP: %fdegC ",setpoint); wait(1); lcd.cls(); lcd.locate(1,1); lcd.printf("SETUP OK"); rs232.printf("SETUP OK"); wait(1); } int main() { rs232.baud(115200); rs232.printf("Control ON-OFF \n\r"); lcd.printf("Control ON-OFF \r\n"); wait(1); lcd.cls(); while (1) { valor_adc=AnalogPin.read()*300;//guardar en entero y mostrar el enetero lcd.locate(1,1); lcd.printf("SP; %fdegC ",setpoint); lcd.locate(1,2); lcd.printf("PV; %fdegC ",valor_adc); rs232.printf("%f,%f \r \n",setpoint,valor_adc); read_kpad(); if(key=='*') { setup_pyrom(); } if(valor_adc>=setpoint) { pinOut=0; } else { pinOut=1;; } wait(0.3); } }