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
main.cpp
- Committer:
- hugocampos
- Date:
- 2021-02-13
- Revision:
- 2:9c890a4ddf0e
- Parent:
- 1:d33dca22f3a1
File content as of revision 2:9c890a4ddf0e:
/*
*Programa com IHM04A1 e bluetooth com 1 motor
*Autor: Hugo Campos
*Data:04/10/2020
*Status: Funcionando
*/
#include "mbed.h"
DigitalOut IN1B (D5);
DigitalOut IN2B (D4);
PwmOut ENB (D2);
Serial bt(PA_11,PA_12); //(D10,D2)
Serial pc(USBTX,USBRX);
int main()
{
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;
}
}
}