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
main.cpp@23:121e3235ccfa, 2017-05-16 (annotated)
- Committer:
- Desertification
- Date:
- Tue May 16 20:06:44 2017 +0000
- Revision:
- 23:121e3235ccfa
- Parent:
- 21:2a91babf5a6d
- Child:
- 24:d91e9b3b5bd5
custom uart finally working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Desertification | 1:6b839581dc9f | 1 | |
Desertification | 1:6b839581dc9f | 2 | #include "mbed.h" |
Thomas Cauwelier |
9:d95984ce5de9 | 3 | #include "Manchester.h" |
Desertification | 23:121e3235ccfa | 4 | //#include "SoftSerial.h" |
Thomas Cauwelier |
15:75f9bd5d7659 | 5 | #include "MySoftSerial.h" |
Desertification | 21:2a91babf5a6d | 6 | #include "SDFileSystem.h" |
Desertification | 21:2a91babf5a6d | 7 | #include "wave_player.h" |
Thomas Cauwelier |
6:0e1973fdfe28 | 8 | |
Desertification | 21:2a91babf5a6d | 9 | |
Desertification | 21:2a91babf5a6d | 10 | Serial usb(USBTX,USBRX); |
Desertification | 21:2a91babf5a6d | 11 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
Desertification | 21:2a91babf5a6d | 12 | |
Desertification | 21:2a91babf5a6d | 13 | |
Desertification | 21:2a91babf5a6d | 14 | void test_player(){ |
Desertification | 21:2a91babf5a6d | 15 | AnalogOut DACout(p18); |
Desertification | 21:2a91babf5a6d | 16 | wave_player waver(&DACout); |
Desertification | 21:2a91babf5a6d | 17 | waver.set_verbosity(0); |
Desertification | 21:2a91babf5a6d | 18 | sd.disk_initialize(); |
Desertification | 21:2a91babf5a6d | 19 | FILE *wave_file; |
Desertification | 21:2a91babf5a6d | 20 | if(wave_file == NULL) { |
Desertification | 21:2a91babf5a6d | 21 | error("Could not open file for write\n"); |
Desertification | 21:2a91babf5a6d | 22 | } |
Desertification | 21:2a91babf5a6d | 23 | printf("Hello, wave world!\n"); |
Desertification | 21:2a91babf5a6d | 24 | wave_file=fopen("/sd/test.wav","r"); |
Desertification | 21:2a91babf5a6d | 25 | waver.play(wave_file); |
Desertification | 21:2a91babf5a6d | 26 | fclose(wave_file); |
Desertification | 21:2a91babf5a6d | 27 | } |
Desertification | 1:6b839581dc9f | 28 | |
Thomas Cauwelier |
13:c111ea1c5990 | 29 | void client(){ |
Thomas Cauwelier |
15:75f9bd5d7659 | 30 | MySoftSerial s(p18,p17); |
Desertification | 21:2a91babf5a6d | 31 | |
Desertification | 23:121e3235ccfa | 32 | s.baud(20000); |
Thomas Cauwelier |
13:c111ea1c5990 | 33 | while (true) { |
Thomas Cauwelier |
13:c111ea1c5990 | 34 | while (!s.readable()); |
Desertification | 14:e29cca7e64b2 | 35 | printf("got %i\r\n",s.getc()); |
Thomas Cauwelier |
13:c111ea1c5990 | 36 | } |
Thomas Cauwelier |
13:c111ea1c5990 | 37 | } |
Thomas Cauwelier |
13:c111ea1c5990 | 38 | |
Thomas Cauwelier |
13:c111ea1c5990 | 39 | void relay(){ |
Desertification | 16:1a0589d846bf | 40 | MySoftSerial s(p17,p18); |
Desertification | 21:2a91babf5a6d | 41 | //MySoftSerial s(LED1,p18); |
Desertification | 23:121e3235ccfa | 42 | s.baud(20000); |
Desertification | 14:e29cca7e64b2 | 43 | int i = 0; |
Desertification | 21:2a91babf5a6d | 44 | while (true) { |
Desertification | 23:121e3235ccfa | 45 | //wait(0.1); |
Desertification | 18:3aeaa22b265d | 46 | for (int j = 0; j < 1; ++j) { |
Desertification | 16:1a0589d846bf | 47 | while(!s.writeable()); |
Desertification | 16:1a0589d846bf | 48 | printf("put %i\r\n", i); |
Desertification | 23:121e3235ccfa | 49 | s.putc(i); |
Desertification | 16:1a0589d846bf | 50 | i++; |
Desertification | 16:1a0589d846bf | 51 | } |
Thomas Cauwelier |
13:c111ea1c5990 | 52 | } |
Thomas Cauwelier |
13:c111ea1c5990 | 53 | } |
Thomas Cauwelier |
13:c111ea1c5990 | 54 | |
Desertification | 23:121e3235ccfa | 55 | #define RELAY 1 |
Thomas Cauwelier |
13:c111ea1c5990 | 56 | |
Desertification | 21:2a91babf5a6d | 57 | int main(){ |
Thomas Cauwelier |
13:c111ea1c5990 | 58 | usb.baud(115200); |
Desertification | 21:2a91babf5a6d | 59 | |
Desertification | 21:2a91babf5a6d | 60 | //test_player(); |
Desertification | 21:2a91babf5a6d | 61 | |
Desertification | 21:2a91babf5a6d | 62 | if (RELAY) { |
Thomas Cauwelier |
13:c111ea1c5990 | 63 | printf("relay\r\n"); |
Thomas Cauwelier |
13:c111ea1c5990 | 64 | relay(); |
Thomas Cauwelier |
12:a070de571ea1 | 65 | } else { |
Thomas Cauwelier |
13:c111ea1c5990 | 66 | printf("client\r\n"); |
Thomas Cauwelier |
13:c111ea1c5990 | 67 | client(); |
Thomas Cauwelier |
6:0e1973fdfe28 | 68 | } |
thoma@THOMAS-CAUWELIER.khbo.be | 4:a07612fbf279 | 69 | } |