Control a RC car via Bluetooth indicating the direction of movement in a LCD using the NUCLEO board STM32F411re
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" // LCD LIBRARY 00003 00004 //*************** 00005 //BLUETOOTH HEADER 00006 //By default the connection is set to 9600 bps 00007 Serial bluetooth(PB_6, PB_3);//Pins used for Serial Comm 00008 //*************** 00009 00010 00011 //*************** 00012 //LCD HEADER 00013 DigitalOut myled(LED1);//* "myled" is the name of the variable 00014 //* "LED1" refers to the integrated LED on the NUCLEO board 00015 // but you can declare any other pin you like 00016 00017 TextLCD ark(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0);// rs, e, d4-d7 -- REGISTER SELECT / ENABLE / DATA-PIN 00018 //Enable A0 00019 //RS A1 00020 //A A2 00021 //B A3 00022 //C A4 00023 //D A5 00024 //*************** 00025 00026 00027 //*************** 00028 //ENCABEZADO PWM 00029 PwmOut led(PB_10);//Sends out the Enable signal for the L293D 00030 DigitalOut pa8(PA_8); //DC motor 1 00031 DigitalOut pa9(PA_9); //DC motor 1 00032 DigitalOut pb4(PB_4); //DC motor 2 00033 DigitalOut pb5(PB_5); //DC motor 2 00034 //*************** 00035 00036 00037 00038 int main() 00039 { 00040 int cont = 0; 00041 // lcd.cls(); To clear screen 00042 bluetooth.baud(9600);//Default is 9600 bps 00043 00044 while(1) { 00045 char c = bluetooth.getc(); // Get daa sent from the bluetooth module 00046 if (c == 's') {// S = Backwards 00047 00048 ark.cls(); 00049 ark.printf("Backwards"); 00050 00051 pa8.write(1); 00052 pa9.write(0); 00053 pb4.write(1); 00054 pb5.write(0); 00055 00056 led.period(8.0f); // 8 second period//8s 00057 led.write(0.25f); // 25% duty cycle, relative to period 00058 } 00059 00060 if (c == 'w') {// 'W' = Forward 00061 ark.cls(); 00062 ark.printf("Forward"); 00063 00064 pa8.write(0); 00065 pa9.write(1); 00066 pb4.write(0); 00067 pb5.write(1); 00068 00069 led.period(8.0f); // 8 second period 00070 led.write(0.25f); // 25% duty cycle, relative to period 00071 } 00072 00073 if (c == 'a') {// 'A' = Left Turn 00074 ark.cls(); 00075 ark.printf("Left Turn"); 00076 00077 pa8.write(0); 00078 pa9.write(1); 00079 pb4.write(0); 00080 pb5.write(0); 00081 00082 led.period(8.0f); // 8 second period 00083 led.write(0.25f); // 25% duty cycle, relative to period 00084 } 00085 00086 if (c == 'd') {// 'D' = Right Turn 00087 ark.cls(); 00088 ark.printf("Right Turn"); 00089 00090 pa8.write(0); 00091 pa9.write(0); 00092 pb4.write(0); 00093 pb5.write(1); 00094 00095 led.period(8.0f); // 8 second period 00096 led.write(0.25f); // 25% duty cycle, relative to period 00097 } 00098 } 00099 }
Generated on Sun Aug 28 2022 04:52:28 by
1.7.2