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:
- 21:2a91babf5a6d
- Parent:
- 18:3aeaa22b265d
- Child:
- 23:121e3235ccfa
--- a/main.cpp Sat May 13 16:21:17 2017 +0200 +++ b/main.cpp Tue May 16 19:29:56 2017 +0000 @@ -1,82 +1,35 @@ #include "mbed.h" -#include "rtos.h" #include "Manchester.h" #include "SoftSerial.h" #include "MySoftSerial.h" +#include "SDFileSystem.h" +#include "wave_player.h" -//Serial out(p9, p10, 3200); //p9 -//Serial in(p13, p14, 3200); //p14 -//Serial usb(USBTX,USBRX); -// -//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[2]; -// read_2_bytes(&in, s); -// char dec[1]; -// bool success = Manchester::decode_manchester(s, 2, dec); -// printf(dec); -// if (!success) { -// printf("#"); -// } -// } else { -// Thread::yield(); -// } -// } -//} -// -//void send_uart(Serial *serial, const char *s, int size) { -// int size_m = size * 2; -// char encoded[size_m]; -// Manchester::encode_manchester(s, size, encoded); -// -// for (int i = 0; i < size_m; ++i) { -// while (!serial->writeable()); -// serial->putc(encoded[i]); -// } -//} -// -//void hardware_uart_test(){ -// -// -// printf("%s\r\n", "hello, term!"); -// -// Thread thread; -// thread.start(receive_uart); -// -// while (true) { -// char tosend[28]; -// Manchester::encode_manchester("hello, term\r\n", 14, tosend); -// send_uart(&out, tosend, 28); -// //wait(1); -// } -//} + +Serial usb(USBTX,USBRX); +SDFileSystem sd(p5, p6, p7, p8, "sd"); + + +void test_player(){ + AnalogOut DACout(p18); + wave_player waver(&DACout); + waver.set_verbosity(0); + sd.disk_initialize(); + FILE *wave_file; + if(wave_file == NULL) { + error("Could not open file for write\n"); + } + printf("Hello, wave world!\n"); + wave_file=fopen("/sd/test.wav","r"); + waver.play(wave_file); + fclose(wave_file); +} void client(){ MySoftSerial s(p18,p17); - s.baud(20000); - //s.format(16, SoftSerial::None, 1); + + s.baud(1); while (true) { while (!s.readable()); printf("got %i\r\n",s.getc()); @@ -85,31 +38,28 @@ void relay(){ MySoftSerial s(p17,p18); - s.baud(20000); - //s.format(16, SoftSerial::None, 1); + //MySoftSerial s(LED1,p18); + s.baud(1); int i = 0; - while (true){ - wait(0.005); + while (true) { + //wait(0.001); for (int j = 0; j < 1; ++j) { while(!s.writeable()); - //printf("put %i\r\n", 0b0101010100110011); - //s.putc(0b0101010100110011); printf("put %i\r\n", i); - //s.putc(0b0000000000000000); - //s.putc(0b0000000000001111); - s.putc(i); + s.putc(0b10101010); i++; } } } -#define RELAY 1 - -Serial usb(USBTX,USBRX); +#define RELAY 0 -int main() { +int main(){ usb.baud(115200); - if (RELAY){ + + //test_player(); + + if (RELAY) { printf("relay\r\n"); relay(); } else {