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.
Dependencies: m3piExpandedCommandSet mbed
Diff: main.cpp
- Revision:
- 0:25cb75cafbb8
- Child:
- 1:5fc064b4c942
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 27 20:33:47 2018 +0000 @@ -0,0 +1,60 @@ +#include "mbed.h" +#include "m3pi.h" + +m3pi m3pi; + +Serial dev(p28,p27); +DigitalOut led1(LED1); + +const int BUFF_LENGTH = 8; + +uint8_t rx_buf[BUFF_LENGTH]; +char str_buf[BUFF_LENGTH]; + +void dev_recv() { + + // toggle the LED whenever a data transmission is received + led1 = !led1; + + int i = 0; + for (i=0; i < BUFF_LENGTH; i++) { + // let buffer empty if it's not ready to be read yet + if (!dev.readable()) { + wait(0.1f); + } + + // if still nothing to read after waiting, must have received + // less than BUFF_LENGTH bytes + if (!dev.readable()) { + break; + } + + uint8_t b = dev.getc(); + rx_buf[i] = b; + str_buf[i] = (char)b; + } + + m3pi.cls(); + m3pi.locate(0,0); + + // print the buffer contents as ASCII on the first line + m3pi.print(str_buf, i); + + // print the buffer length on the second line + m3pi.locate(0, 1); + char str[BUFF_LENGTH] = ""; + sprintf(str, "%d", i); + m3pi.printf(str); + +} + +int main() { + dev.baud(9600); + dev.attach(&dev_recv, Serial::RxIrq); + m3pi.locate(0, 1); + m3pi.printf("BT LE"); + + while(1) { + sleep(); + } +}