![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PID en pantalla LCD con botones incremental, decremental y cambiador de variable (Sp, Kp, Ki, Kd) que tambien suenan con diferente frecuencia cuando se pulsan.
Dependencies: Debounced TextLCD mbed
Fork of pid_teclas by
Revision 1:69f927a70859, committed 2014-04-02
- Comitter:
- walterg
- Date:
- Wed Apr 02 17:37:10 2014 +0000
- Parent:
- 0:9aa80672eb3d
- Commit message:
- This program use three buttons to increment, decrement and change of variable on a LCD, wich is the visual interface of a PID controller that show Sp, Kp, Ki, Kd. Aditionally, each button send a different PWM signal to make sound a little speaker.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 16 17:10:11 2013 +0000 +++ b/main.cpp Wed Apr 02 17:37:10 2014 +0000 @@ -2,9 +2,16 @@ #include "DebouncedIn.h" #include "TextLCD.h" -AnalogIn Vin(PTC2); +float Tdo=1/2093.005; +float Pdo=Tdo/2; +float Tre=1/2637.02; +float Pre=Tre/2; +float Tmi=1/3135.963; +float Pmi=Tmi/2; + + TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 - + DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); @@ -12,6 +19,9 @@ DebouncedIn button2(PTC13); DebouncedIn button3(PTC16); +//DigitalOut Vparlante(PTC5); +PwmOut pw(PTA12); + int C1=0x0F; int sp=0,kp=0,kd=0,ki=0,p=1; int main() @@ -26,11 +36,17 @@ lcd.printf("Kd=%d", kd); lcd.locate(0,0); lcd.printf("Sp=%d", sp); - + + while(1) { if (button1.falling()) { + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + led1 =!led1; if (p==1) { @@ -67,6 +83,11 @@ } if (button2.falling()) { + pw.period(Tre); + pw.pulsewidth(Pre); + wait(0.1); + pw=0; + led2 =!led2; if (p==1) { @@ -127,6 +148,12 @@ } if (button3.falling()) { + + pw.period(Tmi); + pw.pulsewidth(Pmi); + wait(0.1); + pw=0; + led3 =!led3; if (p==1) { @@ -162,4 +189,4 @@ } } } -} +} \ No newline at end of file