This software is for BT_Car_ECE595. It recieves data from android phone via bluetooth and controls the car by using that data.
Revision 1:5513601df33a, committed 2020-03-30
- Comitter:
- prashamshah
- Date:
- Mon Mar 30 06:51:43 2020 +0000
- Parent:
- 0:f3b6143a9685
- Commit message:
- Fixed bugs
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Mar 27 22:34:17 2020 +0000
+++ b/main.cpp Mon Mar 30 06:51:43 2020 +0000
@@ -8,40 +8,40 @@
//serial I/O
Serial bluetooth(PTC15,PTC14); // ptc15: TX, ptc14: RX (frdmk64f)
-Serial pc(PTB17, PTB16);//PTB17 UART1_TX, PTB16 UART1_RX(frdmk64f)
+Serial pc(USBTX, USBRX);
-int dato=0;
+int data;
// Motor A connections
DigitalOut enA(PTC4);
-DigitalOut in1(PTA0);
+DigitalOut in1(PTC2);
DigitalOut in2(PTC3);
// Motor B connections
DigitalOut enB(PTA1);
-DigitalOut in3(PTA2);
-DigitalOut in4(PTB23);
+DigitalOut in3(PTA4);
+DigitalOut in4(PTB12);
int main()
{
+
bluetooth.baud(9600); // Default communication rate of the Bluetooth module
+ pc.baud(9600);
// Turn off motors - Initial state
in1=0;
in2=0;
in3=0;
in4=0;
+
while(1)
{
-
- if(bluetooth.readable())
- {
- dato=bluetooth.getc();
- bluetooth.putc(dato);
- }
+ data=bluetooth.getc();
+ pc.printf("'%d' is recieved.\r\n",data);
+
// Controlling the Motors
- if (dato == 'F')
+ if (data == 1)
{
// Turn on motor A & B
in1=1;
@@ -50,7 +50,7 @@
in4=0;
wait(0.2);
}
- else if (dato== 'B')
+ else if (data== 2)
{
// Turn on motor A & B in reverse direction
in1=0;
@@ -59,7 +59,7 @@
in4=1;
wait(0.2);
}
- else if (dato== 'L')
+ else if (data== 3)
{
// Turn on motor B
in1=0;
@@ -68,7 +68,7 @@
in4=0;
wait(0.2);
}
- else if (dato == 'R')
+ else if (data == 4)
{
// Turn on motor A
in1=1;
@@ -77,7 +77,7 @@
in4=0;
wait(0.2);
}
- else if (dato == 'S')
+ else if (data == 0)
{
// Turn off motor A & B
in1=0;