![](/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
main.cpp@1:29966f67edda, 2014-11-11 (annotated)
- Committer:
- stevenjigo
- Date:
- Tue Nov 11 03:19:39 2014 +0000
- Revision:
- 1:29966f67edda
- Parent:
- 0:a6771cc1a056
This program help to generate a PWM for a Brushless Motor with send parameters from a android system via Bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:a6771cc1a056 | 1 | #include "mbed.h" |
tony63 | 0:a6771cc1a056 | 2 | #include "TextLCD.h" |
tony63 | 0:a6771cc1a056 | 3 | |
stevenjigo | 1:29966f67edda | 4 | Serial device(D14, D15); // tx, rx |
stevenjigo | 1:29966f67edda | 5 | DigitalOut L1(LED1); |
stevenjigo | 1:29966f67edda | 6 | PwmOut pwm(PTA5); |
stevenjigo | 1:29966f67edda | 7 | AnalogIn Sens(A0); |
stevenjigo | 1:29966f67edda | 8 | |
stevenjigo | 1:29966f67edda | 9 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
stevenjigo | 1:29966f67edda | 10 | |
stevenjigo | 1:29966f67edda | 11 | char value; |
stevenjigo | 1:29966f67edda | 12 | float SP=0.05; |
stevenjigo | 1:29966f67edda | 13 | float SPd=0; |
stevenjigo | 1:29966f67edda | 14 | float Cai=0; |
stevenjigo | 1:29966f67edda | 15 | float Asen; |
stevenjigo | 1:29966f67edda | 16 | float p=0; |
stevenjigo | 1:29966f67edda | 17 | float SPdroid; |
tony63 | 0:a6771cc1a056 | 18 | |
tony63 | 0:a6771cc1a056 | 19 | int main() { |
stevenjigo | 1:29966f67edda | 20 | pwm.period_ms(20); |
stevenjigo | 1:29966f67edda | 21 | L1=1; |
stevenjigo | 1:29966f67edda | 22 | lcd.locate(0,0); |
stevenjigo | 1:29966f67edda | 23 | lcd.printf("Bienvenido"); |
stevenjigo | 1:29966f67edda | 24 | lcd.locate(0,1); |
stevenjigo | 1:29966f67edda | 25 | lcd.printf("Control del VTOL"); |
stevenjigo | 1:29966f67edda | 26 | wait(2); |
stevenjigo | 1:29966f67edda | 27 | lcd.cls(); |
stevenjigo | 1:29966f67edda | 28 | lcd.locate(0,0); |
stevenjigo | 1:29966f67edda | 29 | lcd.printf("D:"); |
stevenjigo | 1:29966f67edda | 30 | lcd.locate(5,0); |
stevenjigo | 1:29966f67edda | 31 | lcd.printf("S:"); |
stevenjigo | 1:29966f67edda | 32 | lcd.locate(10,0); |
stevenjigo | 1:29966f67edda | 33 | lcd.printf("BT:"); |
stevenjigo | 1:29966f67edda | 34 | while(1){ |
stevenjigo | 1:29966f67edda | 35 | if(device.readable()){ |
stevenjigo | 1:29966f67edda | 36 | value=device.getc(); |
stevenjigo | 1:29966f67edda | 37 | lcd.cls(); |
stevenjigo | 1:29966f67edda | 38 | lcd.locate(0,0); |
stevenjigo | 1:29966f67edda | 39 | lcd.printf("D:"); |
stevenjigo | 1:29966f67edda | 40 | lcd.locate(5,0); |
stevenjigo | 1:29966f67edda | 41 | lcd.printf("S:"); |
stevenjigo | 1:29966f67edda | 42 | lcd.locate(10,0); |
stevenjigo | 1:29966f67edda | 43 | lcd.printf("BT:"); |
stevenjigo | 1:29966f67edda | 44 | if(value=='0'){ |
stevenjigo | 1:29966f67edda | 45 | SP=0.054; |
stevenjigo | 1:29966f67edda | 46 | } |
stevenjigo | 1:29966f67edda | 47 | if(value=='3'){ |
stevenjigo | 1:29966f67edda | 48 | SP=0.0745; |
stevenjigo | 1:29966f67edda | 49 | } |
stevenjigo | 1:29966f67edda | 50 | if(value=='1'){ |
stevenjigo | 1:29966f67edda | 51 | if(SP<1.00) SP=SP+0.0001; |
stevenjigo | 1:29966f67edda | 52 | } |
stevenjigo | 1:29966f67edda | 53 | if(value=='2'){ |
stevenjigo | 1:29966f67edda | 54 | if(SP>0.00) SP=SP-0.0001; |
stevenjigo | 1:29966f67edda | 55 | } |
stevenjigo | 1:29966f67edda | 56 | if(value=='4'){ |
stevenjigo | 1:29966f67edda | 57 | Cai=1; |
stevenjigo | 1:29966f67edda | 58 | } |
stevenjigo | 1:29966f67edda | 59 | if(value=='X'){ |
stevenjigo | 1:29966f67edda | 60 | SPdroid=device.getc()-48; |
stevenjigo | 1:29966f67edda | 61 | fflush(stdin); |
stevenjigo | 1:29966f67edda | 62 | SP=(SPdroid+1)/200+0.05; |
stevenjigo | 1:29966f67edda | 63 | } |
stevenjigo | 1:29966f67edda | 64 | } |
stevenjigo | 1:29966f67edda | 65 | Asen=(7.21/8)*Sens.read(); |
stevenjigo | 1:29966f67edda | 66 | //pwm=1; |
stevenjigo | 1:29966f67edda | 67 | //wait_ms(SP); |
stevenjigo | 1:29966f67edda | 68 | //pwm=0; |
stevenjigo | 1:29966f67edda | 69 | //wait_ms(20-SP); |
stevenjigo | 1:29966f67edda | 70 | if(Cai==1){ |
stevenjigo | 1:29966f67edda | 71 | while(!Cai==0){ |
stevenjigo | 1:29966f67edda | 72 | SP=SP-0.0001; |
stevenjigo | 1:29966f67edda | 73 | if(SP<0.054){ |
stevenjigo | 1:29966f67edda | 74 | Cai=0; |
stevenjigo | 1:29966f67edda | 75 | } |
stevenjigo | 1:29966f67edda | 76 | wait_ms(50); |
stevenjigo | 1:29966f67edda | 77 | SPd=SP*100; |
stevenjigo | 1:29966f67edda | 78 | lcd.locate(0,1); |
stevenjigo | 1:29966f67edda | 79 | lcd.printf("%.2f ",SPd); |
stevenjigo | 1:29966f67edda | 80 | pwm.write(SP); |
stevenjigo | 1:29966f67edda | 81 | } |
stevenjigo | 1:29966f67edda | 82 | } |
stevenjigo | 1:29966f67edda | 83 | SPd=SP*100; |
stevenjigo | 1:29966f67edda | 84 | lcd.locate(0,1); |
stevenjigo | 1:29966f67edda | 85 | lcd.printf("%.2f %.2f %.2f",SPd,Asen,SPdroid); |
stevenjigo | 1:29966f67edda | 86 | pwm.write(SP); |
stevenjigo | 1:29966f67edda | 87 | } |
stevenjigo | 1:29966f67edda | 88 | } |