Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 2:9c890a4ddf0e, committed 2021-02-13
- Comitter:
- hugocampos
- Date:
- Sat Feb 13 18:51:53 2021 +0000
- Parent:
- 1:d33dca22f3a1
- Commit message:
- Bluetooth
Changed in this revision
SoftSerial.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SoftSerial.lib Fri Nov 16 11:37:29 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/Sissors/code/SoftSerial/#a0029614de72
--- a/main.cpp Fri Nov 16 11:37:29 2018 +0000 +++ b/main.cpp Sat Feb 13 18:51:53 2021 +0000 @@ -1,85 +1,88 @@ -#include "mbed.h" -#include "SoftSerial.h" +/* + *Programa com IHM04A1 e bluetooth com 1 motor + *Autor: Hugo Campos + *Data:04/10/2020 + *Status: Funcionando +*/ -PwmOut mypwm(D6); +#include "mbed.h" -PwmOut mypwm1(D5); - -PwmOut mypwm2(D9); -PwmOut mypwm3(D10); -Serial pc(USBTX,USBRX); -DigitalOut myled(LED1); -DigitalOut aa(D5); -DigitalOut ab(D6); -DigitalOut ba(D9); -DigitalOut bb(D10); +DigitalOut IN1B (D5); +DigitalOut IN2B (D4); +PwmOut ENB (D2); + -SoftSerial bt(D2,D3); //TX RX -char receive; -float vel; +Serial bt(PA_11,PA_12); //(D10,D2) +Serial pc(USBTX,USBRX); -int main() +int main() { - while(1) - { - if (bt.readable()>0) - { - receive=bt.getc(); - //invio=bt.putc(); - //if(receive=='1')myled=!myled; //toggle - vel=receive-48; - vel/=10; - pc.printf("%c %f\n\r", receive, vel); - if(receive=='1'){ - bt.printf("ciao"); - aa=0; - ab=1; - ba=0; - bb=1; - } - if(receive=='2'){ - aa=1; - ab=0; - ba=1; - bb=0; - } - if(receive=='0'){ - aa=0; - ab=0; - ba=0; - bb=0; - } - if(receive=='3'){ - - aa=0; - ab=0; - ba=0; - bb=1; - } - if(receive=='4'){ - - aa=0; - ab=0; - ba=1; - bb=0; - } - if(receive=='5'){ - - aa=0; - ab=1; - ba=0; - bb=0; - } - if(receive=='6'){ - - aa=1; - ab=0; - ba=0; - bb=0; - } - - } - mypwm.write(LED1); + float dutyENB = 0.15; + bt.baud(9600); + + + bt.printf("Connection Established"); + + pc.printf("Connection Established"); + while(1) { + + if (bt.readable()) { + char CONTROL= bt.putc(bt.getc()); + + + if(CONTROL == 'D') { + ENB.write(dutyENB); + IN1B = 0; + IN2B = 1; + bt.printf("motor para direita"); + wait_ms(500); + } + + + if(CONTROL == 'E') { + ENB.write(dutyENB); + IN1B = 1; + IN2B = 0; + bt.printf("motor para esquerda"); + wait_ms(500); + } + if(CONTROL == 'S') { + ENB = 0.0; + IN1B = 0; + IN2B = 0; + pc.printf("motor parado"); + wait_ms(500); + } + ENB = 0; + + } + + if (pc.readable()) { + char CONTROL= pc.putc(pc.getc()); + if(CONTROL == 'E') { + ENB.write(dutyENB); + IN1B = 1; + IN2B = 0; + pc.printf("motor para esquerda"); + wait_ms(500); + } + if(CONTROL == 'D') { + ENB.write(dutyENB); + IN1B = 0; + IN2B = 1; + pc.printf("motor para direita"); + wait_ms(500); + } + if(CONTROL == 'S') { + ENB = 0.0; + IN1B = 0; + IN2B = 0; + pc.printf("motor parado"); + wait_ms(500); + } + ENB=0.0; + } } -} + +} \ No newline at end of file