Thipawan Pairam
/
BluewithCar
Control car by bluetooth.
Diff: main.cpp
- Revision:
- 0:e35b1281c62b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Oct 28 09:42:08 2017 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" + +Serial blue (PA_9, PA_10 ); +PwmOut PwmA(D3); +PwmOut PwmB(D6); +PwmOut PwmA1(D5); +PwmOut PwmB1(D9); + + int main(){ + blue.baud(9600); + while(1){ + if(blue.readable()){ + char key = blue.putc(blue.getc()); + PwmA.period_ms(5); + PwmB.period_ms(5); + PwmA1.period_ms(5); + PwmB1.period_ms(5); + if(key == 'f'){ + PwmA.pulsewidth_ms(3); + PwmB.pulsewidth_ms(3); + PwmA1.pulsewidth_ms(0); + PwmB1.pulsewidth_ms(0); + + } + else if(key =='b'){ + PwmA.pulsewidth_ms(0); + PwmB.pulsewidth_ms(0); + PwmA1.pulsewidth_ms(3); + PwmB1.pulsewidth_ms(3); + } + else if(key =='l'){ + PwmA.pulsewidth_ms(3); + PwmB.pulsewidth_ms(0); + PwmA1.pulsewidth_ms(0); + PwmB1.pulsewidth_ms(3); + } + else if(key =='r'){ + PwmA.pulsewidth_ms(0); + PwmB.pulsewidth_ms(3); + PwmA1.pulsewidth_ms(3); + PwmB1.pulsewidth_ms(0); + } + else{ + PwmA.pulsewidth_ms(0); + PwmB.pulsewidth_ms(0); + PwmA1.pulsewidth_ms(0); + PwmB1.pulsewidth_ms(0); + + } + } + } +}