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.
main.cpp
00001 /* Includes ------------------------------------------------------------------*/ 00002 #include "mbed.h" 00003 //#include "Servo.h" 00004 00005 Serial bt(PA_9,PA_10); //PB_6,PA_10 00006 Serial pc(USBTX,USBRX); 00007 //Servo myservo(D14); 00008 DigitalOut MotorA_in1(PB_5); //PB_5 D4 00009 DigitalOut MotorA_in2(PB_3); //PA_10 D3 00010 DigitalOut MotorB_in1(PB_4); //PA_9 D5 00011 DigitalOut MotorB_in2(PA_8); //PA_8 D7 00012 00013 //char cmd; 00014 00015 int main() 00016 { 00017 bt.baud(9600); 00018 while(1) 00019 { 00020 if (bt.readable()) 00021 { pc.printf("bluetooth connected\n"); 00022 char cmd= bt.putc(bt.getc()); // bt.getc(); 00023 //pc.printf("%d \n\r",cmd); 00024 /* MotorA_in1 = 0; 00025 MotorA_in2 = 1; 00026 MotorB_in1 = 0; 00027 MotorB_in2 = 1;*/ 00028 if(cmd == 'F') 00029 { 00030 //forward 00031 MotorA_in1 = 0; 00032 MotorA_in2 = 1; 00033 MotorB_in1 = 0; 00034 MotorB_in2 = 1; 00035 pc.printf("motor forward\n"); 00036 } 00037 else if(cmd == 'B') 00038 { 00039 //backward 00040 MotorA_in1 = 1; 00041 MotorA_in2 = 0; 00042 MotorB_in1 = 1; 00043 MotorB_in2 = 0; 00044 pc.printf("motor backward\n"); 00045 } 00046 else if(cmd == 'L') 00047 { 00048 //backward 00049 MotorA_in1 = 0; 00050 MotorA_in2 = 1; 00051 MotorB_in1 = 0; 00052 MotorB_in2 = 0; 00053 pc.printf("motor left\n"); 00054 } 00055 else if(cmd == 'R') 00056 { 00057 //backward 00058 MotorA_in1 = 0; 00059 MotorA_in2 = 0; 00060 MotorB_in1 = 0; 00061 MotorB_in2 = 1; 00062 pc.printf("motor right\n"); 00063 } 00064 else{ 00065 MotorA_in1 = 0; 00066 MotorA_in2 = 0; 00067 MotorB_in1 = 0; 00068 MotorB_in2 = 0; 00069 pc.printf("motor stop\n"); 00070 } 00071 } 00072 else {pc.printf("bluetooth not connected\n");} 00073 //wait(0.2); 00074 } 00075 00076 } 00077
Generated on Sun Sep 22 2024 15:56:31 by
1.7.2