Craig Evans
/
1620_App_Board_DAC_Melody
Using DAC to play a melody
Fork of 1620_App_Board_UART_getc by
main.cpp
- Committer:
- eencae
- Date:
- 2017-03-13
- Revision:
- 1:9840610e5ff2
- Parent:
- 0:8ccb53688328
File content as of revision 1:9840610e5ff2:
/* ELEC1620 Application Board Example Example of the Tone library to interface with the DAC (c) Dr Craig A. Evans, University of Leeds, March 2017 */ #include "mbed.h" #include "Tone.h" Tone dac(p18); // Super Mario Theme Tune const int note_array[] = { NOTE_E7, NOTE_E7, 0, NOTE_E7, 0, NOTE_C7, NOTE_E7, 0, NOTE_G7, 0, 0, 0, NOTE_G6, 0, 0, 0, NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0,NOTE_C7, NOTE_D7, NOTE_B6, 0, 0, NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0,NOTE_C7, NOTE_D7, NOTE_B6, 0, 0 }; // 8 corresponds to 1/8 const int duration_array[] = { 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 6,6,6, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8, 6,6,6, 8,8,8,8, 8,8,8,8, 8,8,8,8, }; int main() { dac.init(); int n = sizeof(note_array)/sizeof(int); // tell it the number of notes, arrays, BPM and whether to repeat dac.play_melody(n,note_array,duration_array,120.0,true); }