
Modulo Bluetooh controla PWM de un LED
Revision 0:9f953d3871c9, committed 2019-07-07
- Comitter:
- junmorenodi
- Date:
- Sun Jul 07 17:37:54 2019 +0000
- Child:
- 1:ccce94774ade
- Commit message:
- ModuloBLuetooth
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jul 07 17:37:54 2019 +0000 @@ -0,0 +1,91 @@ +#include "mbed.h" +Serial pc(USBTX, USBRX); +Serial blue(PG_14,PG_9); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +PwmOut ledPWM(PA_3); + + + + + +int main() { + blue.baud(9600); + pc.baud(9600); + pc.printf("Start \r\n"); + float data_sent=0; + float unid=0; + float dec=0; + float cent=0; + char ok='0'; + float new_data=0; + float period=0.001; + float duty=1.0f; + + /* + while(1) { + + if(blue.readable()) + { + data_sent=blue.getc(); + //pc.putc(blue.getc()); + pc.putc(data_sent); + led1=!led1; + } + if(pc.readable()) + { data_sent=pc.getc(); + //blue.putc(pc.getc()); + blue.putc(data_sent+1); + led2=!led2; + } + + + }*/ + while(1){ + + for (int i=0; i<3;i++) + { + + data_sent=blue.getc(); + data_sent=data_sent-'0'; + + if (i==0){ + cent=data_sent*100; + } + if (i==1){ + dec=data_sent*10; + } + if (i==2){ + unid=data_sent; + } + + + } + wait(1); + + new_data=unid+dec+cent; + + if (new_data==100.0){ + led2=1; + led3=0; + } + else { + led3=1; + led2=0; + } + + duty=new_data/100; + + ledPWM.period(period); + ledPWM.write(duty); + + pc.printf("Valor Data_Sent: %.1f \r\n", new_data); + pc.printf("PWM Duty Cycle: %.2f %\r\n", duty*100); + } + + + + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jul 07 17:37:54 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file