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: SoftSerial SDFileSystem mbed wave_player
Diff: main.cpp
- Revision:
- 10:071b7cc8b0ff
- Parent:
- 9:d95984ce5de9
- Child:
- 11:e462ce7a42b9
--- a/main.cpp Wed May 03 00:59:46 2017 +0200 +++ b/main.cpp Wed May 03 09:40:14 2017 +0200 @@ -6,18 +6,36 @@ Serial out(p9, p10, 3200); //p9 Serial in(p13, p14, 3200); //p14 +char *read_2_bytes(Serial *serial, char out[2]) { + int i = 0; + while (true) { + while (!serial->readable()); + char c = (char) serial->getc(); + if (c == 0b11100011) //no data flag + continue; + else{ + out[i] = c; + i++; + } + + if (i == 2){ + break; + } + } + return out; +} + void receive_uart() { - while (true){ - if(in.readable()){ - char s[28]; - in.gets(s, 28); - - char dec[14]; - Manchester::decode_manchester(s,28,dec); + while (true) { + if (in.readable()) { + char s[2]; + read_2_bytes(&in, s); + char dec[1]; + Manchester::decode_manchester(s, 2, dec); printf(dec); - }else{ + } else { Thread::yield(); } } @@ -29,11 +47,11 @@ Thread thread; thread.start(receive_uart); - while (true){ + while (true) { while (!out.writeable()); char tosend[28]; - Manchester::encode_manchester("hello, term\r\n",14,tosend); + Manchester::encode_manchester("hello, term\r\n", 14, tosend); out.printf(tosend); wait(1); }