Control car by bluetooth.

Dependencies:   mbed

main.cpp

Committer:
Pairam
Date:
2017-10-28
Revision:
0:e35b1281c62b

File content as of revision 0:e35b1281c62b:

#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);
          
            }
        }         
    }
}