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@24:d91e9b3b5bd5, 2017-05-17 (annotated)
- Committer:
- Thomas Cauwelier 
- Date:
- Wed May 17 00:10:42 2017 +0200
- Revision:
- 24:d91e9b3b5bd5
- Parent:
- 23:121e3235ccfa
- Child:
- 26:1c8a7d0bb4b7
add relay logic
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 | 24:d91e9b3b5bd5 | 8 | #include "Relay.h" | 
| Desertification | 21:2a91babf5a6d | 9 | |
| Desertification | 21:2a91babf5a6d | 10 | |
| Desertification | 21:2a91babf5a6d | 11 | void test_player(){ | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 12 | SDFileSystem sd(p5, p6, p7, p8, "sd"); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 13 | Serial usb(USBTX,USBRX); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 14 | usb.baud(115200); | 
| 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 | 24:d91e9b3b5bd5 | 29 | void test_client(){ | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 30 | Serial usb(USBTX,USBRX); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 31 | usb.baud(115200); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 32 | |
| Thomas Cauwelier | 15:75f9bd5d7659 | 33 | MySoftSerial s(p18,p17); | 
| Desertification | 21:2a91babf5a6d | 34 | |
| Desertification | 23:121e3235ccfa | 35 | s.baud(20000); | 
| Thomas Cauwelier | 13:c111ea1c5990 | 36 | while (true) { | 
| Thomas Cauwelier | 13:c111ea1c5990 | 37 | while (!s.readable()); | 
| Desertification | 14:e29cca7e64b2 | 38 | printf("got %i\r\n",s.getc()); | 
| Thomas Cauwelier | 13:c111ea1c5990 | 39 | } | 
| Thomas Cauwelier | 13:c111ea1c5990 | 40 | } | 
| Thomas Cauwelier | 13:c111ea1c5990 | 41 | |
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 42 | void test_relay(){ | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 43 | Serial usb(USBTX,USBRX); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 44 | usb.baud(115200); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 45 | |
| Desertification | 16:1a0589d846bf | 46 | MySoftSerial s(p17,p18); | 
| Desertification | 21:2a91babf5a6d | 47 | //MySoftSerial s(LED1,p18); | 
| Desertification | 23:121e3235ccfa | 48 | s.baud(20000); | 
| Desertification | 14:e29cca7e64b2 | 49 | int i = 0; | 
| Desertification | 21:2a91babf5a6d | 50 | while (true) { | 
| Desertification | 23:121e3235ccfa | 51 | //wait(0.1); | 
| Desertification | 18:3aeaa22b265d | 52 | for (int j = 0; j < 1; ++j) { | 
| Desertification | 16:1a0589d846bf | 53 | while(!s.writeable()); | 
| Desertification | 16:1a0589d846bf | 54 | printf("put %i\r\n", i); | 
| Desertification | 23:121e3235ccfa | 55 | s.putc(i); | 
| Desertification | 16:1a0589d846bf | 56 | i++; | 
| Desertification | 16:1a0589d846bf | 57 | } | 
| Thomas Cauwelier | 13:c111ea1c5990 | 58 | } | 
| Thomas Cauwelier | 13:c111ea1c5990 | 59 | } | 
| Thomas Cauwelier | 13:c111ea1c5990 | 60 | |
| Desertification | 23:121e3235ccfa | 61 | #define RELAY 1 | 
| Thomas Cauwelier | 13:c111ea1c5990 | 62 | |
| Desertification | 21:2a91babf5a6d | 63 | int main(){ | 
| Desertification | 21:2a91babf5a6d | 64 | |
| Desertification | 21:2a91babf5a6d | 65 | //test_player(); | 
| Desertification | 21:2a91babf5a6d | 66 | |
| Desertification | 21:2a91babf5a6d | 67 | if (RELAY) { | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 68 | Relay relay(p17,20000,USBTX,USBRX,115200); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 69 | relay.run(); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 70 | //test_relay(); | 
| Thomas Cauwelier | 12:a070de571ea1 | 71 | } else { | 
| Thomas Cauwelier | 13:c111ea1c5990 | 72 | printf("client\r\n"); | 
| Thomas Cauwelier | 24:d91e9b3b5bd5 | 73 | test_client(); | 
| Thomas Cauwelier | 6:0e1973fdfe28 | 74 | } | 
| thoma@THOMAS-CAUWELIER.khbo.be | 4:a07612fbf279 | 75 | } |