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.
Diff: main.cpp
- Revision:
- 5:47575b30c19a
- Parent:
- 4:9c0216df5c8e
- Child:
- 7:d8f4e9d92ab5
--- a/main.cpp Thu Feb 04 18:20:16 2016 +0000
+++ b/main.cpp Thu Feb 04 20:18:39 2016 +0000
@@ -1,100 +1,28 @@
#include "mbed.h"
-
-#define SOP 's'
-#define EOP 'e'
+#include "HC05.h"
DigitalOut myLed(LED1);
Serial pc(USBTX, USBRX); // tx, rx
-Serial myBT(D1, D0); //Tx, Rx
-int index = 0;
-
-int xVal = 0, yVal = 0, cVal = 0;
-
-char btData[20];
+HC05 myBT(D1, D0); // tx, rx
-bool started = false;
-bool ended = false;
+int16_t xVal=0, yVal=0, cVal=0;
-int main() {
-
+int main()
+{
pc.baud(115200);
- myBT.baud(9600);
pc.printf("\r\n -= Serial Bluetooth test \r\n");
- char btChar; //Char to hold the bluetooth command lette
-
- while(1) {
- while(myBT.readable())
- {
- btChar = myBT.getc();
-
- if(btChar == SOP)
- {
- index = 0;
- btData[index] = '\0';
- started = true;
- ended = false;
- }
- else if(btChar == EOP)
- {
- ended = true;
- break;
- }
- else
- {
- if(index < 19)
- {
- btData[index] = btChar;
- index++;
- btData[index] = '\0';
- }
- }
- }
+ while(1)
+ {
+ myBT.getValue(&xVal, &yVal, &cVal);
- if(started && ended)
+ if(xVal || yVal || cVal > 0)
{
- char *name = strtok(btData, "=");
-
- while(name)
- {
- char *valToken = strtok(NULL, ",");
- if(valToken)
- {
- int val = atoi(valToken);
-
- if(strcmp(name, "X") == 0)
- {
- xVal = val;
- }
- else if(strcmp(name, "Y") == 0)
- {
- yVal = val;
- }
- else if(strcmp(name, "C") == 0)
- {
- cVal = val;
- }
- }
- name = strtok(NULL, "=");
- }
-
- // Reset for the next packet
- started = false;
- ended = false;
- index = 0;
- btData[index] = '\0';
pc.printf("X= %d, Y= %d, C= %d \r\n",xVal, yVal, cVal);
}
-
-// myBT.scanf("%c", &btChar); //Read a letter from the bluetooth stream.
-// pc.printf("btChar: %c ", btChar);
-
myLed = !myLed;
-// wait(0.5);
-// pc.printf("loop %d\r\n", counter);
-// counter++;
}
}