Segundo ejercicio

Dependencies:   Debounced TextLCDa mbed

main.cpp

Committer:
mandres7
Date:
2013-12-04
Revision:
0:dff84c672b7e

File content as of revision 0:dff84c672b7e:

#include "mbed.h"
#include "TextLCD.h"
#include "DebouncedIn.h"
 
Timer timer1;
TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7
DigitalOut myled(LED1);
AnalogOut Aout(PTE30);
AnalogIn Ain(PTC2);
DebouncedIn Arriba(PTE2);
DebouncedIn Abajo(PTE3);
DebouncedIn Ganancia(PTE4);
 
float i=0.7; // set point
float j=0; // salida planta
float k=0; // entrada planta
float m=3.4; // ganancia
float js=0;
float ji=1; 
float re=0;
float jo=0;
float jd=0;
float t=0; //tiempo
 
int main() {
//float Setpoint=0.6;
    while(1) {
        
        if(Arriba.falling()){
        i+=0.01;
        }
        
        if(Abajo.falling()){
        i-=0.01;
        }
        
        if(Ganancia.falling()){
        m+=0.01;
        }
                
        if(i<0.999){
       
        j=Ain;
        k=m*(i-j);
        Aout=k;
        wait(0.1);
        jo=j-jo;
        lcd.locate(0,0);
        lcd.printf("y:%.3f jd:%.2f", j, jd);
        lcd.locate(0,1);
        lcd.printf("t:%f",t);
        lcd.locate(10,1);
        lcd.printf("K:%.2f",m);
        }
        
        if(j>js){
        js=j;
        }
        
        if(j<ji){
        ji=j;
        }
        //wait(0.2);
        jo=j;
        re=js-ji;
        jd=ji+(re/2);
        
        if(abs(jd-j)<=0.001){
        
        t=timer1.read();
        timer1.stop();
        timer1.reset();
        timer1.start();
        
        } 
  
    }
    
}