Demo program of the wave_player library working with mbed-os v5. For ECE 4180 Lab 3 Extra Extra credit.
Revision 0:9ed9bcd7cc87, committed 2019-10-01
- Comitter:
- HighTide
- Date:
- Tue Oct 01 00:41:43 2019 +0000
- Child:
- 1:8f625551de9f
- Commit message:
- Initial commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Oct 01 00:41:43 2019 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Oct 01 00:41:43 2019 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "wave_player.h"
+
+// LED Components
+PwmOut led(LED1);
+
+// SD File System Components
+SDBlockDevice sd(p5, p6, p7, p8);
+FATFileSystem fs("sd");
+
+// Audio Components
+AnalogOut dac(p18);
+PwmOut speaker(p25);
+wave_player wav(&dac, &speaker);
+
+Thread led_thread, audio_thread;
+
+void led_siren() {
+ const int build_time = 100;
+ while (1) {
+ //LED warm up effect using PWM
+ for(int i=0; i<build_time; i++) {
+ led = i / (float) build_time;
+ ThisThread::sleep_for(1000.0*0.02);
+ }
+ //LED at full brightness level
+ led = 1.0;
+ ThisThread::sleep_for(1000.0*0.25);
+ //LED cool down effect using PWM
+ for(int i=build_time-1; i>0; i--) {
+ led = i/ (float) build_time;
+ ThisThread::sleep_for(1000.0*0.02);
+ }
+ //LED off
+ led = 0.0;
+ ThisThread::sleep_for(1000.0*1.5);
+ }
+}
+
+void play_audio() {
+ FILE * wav_file;
+ speaker.period(1.0/1000000.0);
+ while (1) {
+ sd.init();
+ fs.mount(&sd);
+ wav_file = fopen("/sd/siren.wav", "r");
+ wav.play(wav_file);
+ fclose(wav_file);
+ sd.deinit();
+ fs.unmount();
+ }
+}
+
+// main() runs in its own thread in the OS
+int main()
+{
+ led_thread.start(led_siren);
+ audio_thread.start(play_audio);
+ while (true) {
+ ThisThread::sleep_for(500);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Oct 01 00:41:43 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#20975127893e0a24e278dbdca6b271e723002910
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Tue Oct 01 00:41:43 2019 +0000
@@ -0,0 +1,7 @@
+{
+ "target_overrides": {
+ "*": {
+ "target.components_add": ["SD"]
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Tue Oct 01 00:41:43 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/sravet/code/wave_player/#106018dd7db9