Tarea2-Versión1. Uso de 3 botones para cambiar los parámetros de un PID tal que al presionar cualquiera de los 3 botones se escucha un sonido con distinta frecuencia
Dependencies: Debounced TextLCD mbed
Fork of Tarea2-V1 by
main.cpp
- Committer:
- juniorACA
- Date:
- 2014-05-12
- Revision:
- 2:8782da14cf8f
- Parent:
- 1:84592eb27d11
File content as of revision 2:8782da14cf8f:
#include "mbed.h" #include "DebouncedIn.h" #include "TextLCD.h" AnalogIn Vin(PTC2); TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 PwmOut sonido(PTA12); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DebouncedIn button1(PTC12); DebouncedIn button2(PTC13); DebouncedIn button3(PTC16); int C1=0x0F; int sp=0,kp=0,kd=0,ki=0,p=1; float Dd=10; float pp=30; float Fi; int main() { lcd.cls(); lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD lcd.locate(8,0); lcd.printf("kp=%d", kp); lcd.locate(0,1); lcd.printf("Ki=%d", ki); lcd.locate(8,1); lcd.printf("Kd=%d", kd); lcd.locate(0,0); lcd.printf("Sp=%d", sp); while(1) {Fi=(Dd)*100; pp=(1/Fi); sonido.period(pp); if (button1.falling()) { sonido.write(0.1); wait(0.1); sonido.write(0); wait(0.1); led1 =!led1; if (p==1) { ++sp; lcd.locate(3,0); lcd.printf(" "); lcd.locate(3,0); lcd.printf("%d", sp); } else if (p==2) { ++kp; lcd.locate(11,0); lcd.printf(" "); lcd.locate(11,0); lcd.printf("%d", kp); } else if (p==3) { ++ki; lcd.locate(3,1); lcd.printf(" "); lcd.locate(3,1); lcd.printf("%d", ki); } else if (p==4) { ++kd; lcd.locate(11,1); lcd.printf(" "); lcd.locate(11,1); lcd.printf("%d", kd); } } if (button2.falling()) { sonido.write(0.5); wait(0.1); sonido.write(0.0); wait(0.1); led2 =!led2; if (p==1) { if (sp==0) // no mostrar nada { } else { --sp; lcd.locate(3,0); lcd.printf(" "); lcd.locate(3,0); lcd.printf("%d", sp); } } if (p==2) { if (kp==0) // no mostrar nada { } else { --kp; lcd.locate(11,0); lcd.printf(" "); lcd.locate(11,0); lcd.printf("%d", kp); } } if (p==3) { if (ki==0) // no mostrar nada { } else { --ki; lcd.locate(3,1); lcd.printf(" "); lcd.locate(3,1); lcd.printf("%d", ki); } } if (p==4) { if (kd==0) // no mostrar nada { } else { --kd; lcd.locate(11,1); lcd.printf(" "); lcd.locate(11,1); lcd.printf("%d", kd); } } } if (button3.falling()) { sonido.write(0.8); wait(0.1); sonido.write(0.0); wait(0.1); led3 =!led3; if (p==1) { ++p; lcd.locate(11,0); lcd.printf("%d", kp); } else if (p==2) { ++p; lcd.locate(3,1); lcd.printf("%d", ki); lcd.locate(3,1); } else if (p==3) { ++p; lcd.locate(11,1); lcd.printf("%d", kd); } else if (p==4) { p=1; lcd.locate(3,0); lcd.printf("%d", sp); } } } }