pwm recibe la entrada del pid y varia el ciclo de trabajo y = 2.5x - 1.5 presion dice si esta lleno o que se yo (actualizar valores)

Dependencies:   TextLCD mbed

Fork of PWM by proyectotecnicas

Revision:
4:f30ca1a8ca5f
Parent:
3:7de9f8f4a15e
--- a/main.cpp	Mon Dec 07 19:30:24 2015 +0000
+++ b/main.cpp	Thu Dec 10 13:42:30 2015 +0000
@@ -2,9 +2,9 @@
 #include "TextLCD.h"
 #include "AnalogIn.h"
 PwmOut pwmsal(PTD2);
-AnalogIn pwment(PTB1);
+AnalogIn pident(PTB1);
 Serial pc(USBTX,USBRX);
-float valorpwm;
+float valorpwm, valorpid;
 TextLCD lcd(PTD3, PTA12, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2);
 AnalogIn presionin(PTB3);
 float caspresion;
@@ -12,33 +12,41 @@
 
 int main()
 {
-    
-    while(1){
-    
-      caspresion = presionin.read() * 3.3;
+    pc.baud(115200);
+    pwmsal.period(7);
+
+    while(1) {
+
+        caspresion = presionin.read() * 3.3;
         lcd.cls();
         lcd.locate(0,1);
         lcd.printf("%.2f",caspresion);
-        
-        if(caspresion >= 2.34){
+
+        if(caspresion >= 2.34) {
             lcd.locate(0,0);
             lcd.printf("maximo");
-            }
-        
-        if(caspresion >= 1.68 && caspresion <= 1.85){
+        }
+
+        if(caspresion >= 1.68 && caspresion <= 1.85) {
             lcd.locate(0,0);
             lcd.printf("medio");
-            }
-        
-        if(caspresion <= 1.03){
+        }
+
+        if(caspresion <= 1.03) {
             lcd.locate(0,0);
             lcd.printf("minimo");
-            }    
-        
-    pc.baud(115200);
-    pwmsal.period(5);
-    valorpwm = pwment.read();
-    pwmsal.write(valorpwm);
-    wait(1);
+        }
+
+        valorpid = pident.read();
+
+        if(valorpid >1)
+            pwmsal.write(1);
+        else if(valorpid <= 1 && valorpid >= 0.6) {
+            valorpwm = 2.5 * valorpid - 1.5;
+            pwmsal.write(valorpwm);
+        } else
+            pwmsal.write(0);
+
+        wait(1);
     }
 }