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
main.cpp
- Committer:
- kkillebrew
- Date:
- 2018-05-27
- Revision:
- 0:25cb75cafbb8
- Child:
- 1:5fc064b4c942
File content as of revision 0:25cb75cafbb8:
#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(); } }