![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This program is the begin to realize a control for a VTOL system from a android phone via bluetooth and show the variables in a LCD
Fork of LCD_FRDM_KL25Z by
Diff: main.cpp
- Revision:
- 1:29966f67edda
- Parent:
- 0:a6771cc1a056
--- a/main.cpp Tue Sep 03 16:16:26 2013 +0000 +++ b/main.cpp Tue Nov 11 03:19:39 2014 +0000 @@ -1,11 +1,88 @@ -// Hello World! for the TextLCD -// EJEMPLO CON UN LCD PARA EL MODULO FRDM-KL25Z - #include "mbed.h" #include "TextLCD.h" -TextLCD lcd(PTE0, PTE1, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 +Serial device(D14, D15); // tx, rx +DigitalOut L1(LED1); +PwmOut pwm(PTA5); +AnalogIn Sens(A0); + +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 + +char value; +float SP=0.05; +float SPd=0; +float Cai=0; +float Asen; +float p=0; +float SPdroid; int main() { - lcd.printf("Hello World!\n"); -} + pwm.period_ms(20); + L1=1; + lcd.locate(0,0); + lcd.printf("Bienvenido"); + lcd.locate(0,1); + lcd.printf("Control del VTOL"); + wait(2); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("D:"); + lcd.locate(5,0); + lcd.printf("S:"); + lcd.locate(10,0); + lcd.printf("BT:"); + while(1){ + if(device.readable()){ + value=device.getc(); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("D:"); + lcd.locate(5,0); + lcd.printf("S:"); + lcd.locate(10,0); + lcd.printf("BT:"); + if(value=='0'){ + SP=0.054; + } + if(value=='3'){ + SP=0.0745; + } + if(value=='1'){ + if(SP<1.00) SP=SP+0.0001; + } + if(value=='2'){ + if(SP>0.00) SP=SP-0.0001; + } + if(value=='4'){ + Cai=1; + } + if(value=='X'){ + SPdroid=device.getc()-48; + fflush(stdin); + SP=(SPdroid+1)/200+0.05; + } + } + Asen=(7.21/8)*Sens.read(); + //pwm=1; + //wait_ms(SP); + //pwm=0; + //wait_ms(20-SP); + if(Cai==1){ + while(!Cai==0){ + SP=SP-0.0001; + if(SP<0.054){ + Cai=0; + } + wait_ms(50); + SPd=SP*100; + lcd.locate(0,1); + lcd.printf("%.2f ",SPd); + pwm.write(SP); + } + } + SPd=SP*100; + lcd.locate(0,1); + lcd.printf("%.2f %.2f %.2f",SPd,Asen,SPdroid); + pwm.write(SP); + } +} \ No newline at end of file