![](/media/cache/profiles/a36470cf1f8e5aaf38466d65bd080699.jpg.50x50_q85.jpg)
DAC example playing a single tone
Fork of 1620_App_Board_UART_getc by
Revision 1:19c0920a6623, committed 2017-03-13
- Comitter:
- eencae
- Date:
- Mon Mar 13 19:49:25 2017 +0000
- Parent:
- 0:8ccb53688328
- Commit message:
- Initial commit
Changed in this revision
diff -r 8ccb53688328 -r 19c0920a6623 ShiftReg.lib --- a/ShiftReg.lib Fri Mar 03 15:10:39 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/eencae/code/ShiftReg/#33b34e0ed72c
diff -r 8ccb53688328 -r 19c0920a6623 Tone.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tone.lib Mon Mar 13 19:49:25 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/eencae/code/Tone/#836cdf67dbdb
diff -r 8ccb53688328 -r 19c0920a6623 main.cpp --- a/main.cpp Fri Mar 03 15:10:39 2017 +0000 +++ b/main.cpp Mon Mar 13 19:49:25 2017 +0000 @@ -1,48 +1,26 @@ /* ELEC1620 Application Board Example -Example of using getc to receive data from the PC to control -the application board +Example of the Tone library to interface with the DAC -(c) Dr Craig A. Evans, University of Leeds, Feb 2017 +(c) Dr Craig A. Evans, University of Leeds, March 2017 */ #include "mbed.h" -#include "ShiftReg.h" // include ShiftReg library +#include "Tone.h" -ShiftReg shift; // create ShiftReg object -Serial pc(USBTX,USBRX); +Tone dac(p18); int main() { - // values for 0 - 9 in hex - int seven_seg_array [] = { - 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67 - }; + dac.init(); - // write 0 to 7-seg to turn it off - shift.write(0x00); - - while(1) { + while (1) { - // readable tells us if a character is waiting to be read - if ( pc.readable() ) { - // if one is there, then read in using getc - char c = pc.getc(); - - // check if it is a digit that has been received - note ' ' for char - if (c >= '0' && c <= '9') { - // the received char is in ASCII so convert to int by substracting - // the ASCII value of '0' - int value = c - '0'; - - // make that value appear on the 7-seg display - shift.write(seven_seg_array [value]); - - } - + for(float f = 100.0; f <=1000.0 ; f += 100.0) { + dac.play(f,0.2); + wait(0.25); } - } }