plays sound via SD card
Dependencies: mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem
main.cpp@5:63f0d732f83c, 2019-12-09 (annotated)
- Committer:
- jingyitaro
- Date:
- Mon Dec 09 21:34:02 2019 +0000
- Revision:
- 5:63f0d732f83c
- Parent:
- 4:79863d2ea5a0
deleted everything and left playSound only
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 2:a69c8c5f5b03 | 1 | // example to test the mbed Lab Board lcd lib with the mbed rtos |
4180_1 | 4:79863d2ea5a0 | 2 | // Pot1 changes the contrast |
4180_1 | 4:79863d2ea5a0 | 3 | // Pot2 changes the speed of the sin wave |
dreschpe | 1:1c6a9eaf55b5 | 4 | |
dreschpe | 0:f6a57b843f79 | 5 | #include "mbed.h" |
dreschpe | 0:f6a57b843f79 | 6 | #include "rtos.h" |
dreschpe | 0:f6a57b843f79 | 7 | #include "stdio.h" |
jingyitaro | 5:63f0d732f83c | 8 | #include "SDFileSystem.h" |
jingyitaro | 5:63f0d732f83c | 9 | #include "wave_player.h" |
4180_1 | 4:79863d2ea5a0 | 10 | |
jingyitaro | 5:63f0d732f83c | 11 | DigitalOut led1(LED1); |
jingyitaro | 5:63f0d732f83c | 12 | DigitalOut led2(LED2); |
jingyitaro | 5:63f0d732f83c | 13 | DigitalOut led3(LED3); |
jingyitaro | 5:63f0d732f83c | 14 | |
jingyitaro | 5:63f0d732f83c | 15 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
jingyitaro | 5:63f0d732f83c | 16 | AnalogOut DACout(p18); |
jingyitaro | 5:63f0d732f83c | 17 | wave_player waver(&DACout); |
dreschpe | 2:a69c8c5f5b03 | 18 | |
4180_1 | 4:79863d2ea5a0 | 19 | // mutex to make the lcd lib thread safe |
jingyitaro | 5:63f0d732f83c | 20 | Mutex spk_mutex; |
dreschpe | 0:f6a57b843f79 | 21 | |
dreschpe | 0:f6a57b843f79 | 22 | |
4180_1 | 4:79863d2ea5a0 | 23 | // Thread 6 |
4180_1 | 4:79863d2ea5a0 | 24 | // Speaker |
4180_1 | 4:79863d2ea5a0 | 25 | void thread6(void const *args) |
4180_1 | 4:79863d2ea5a0 | 26 | { |
jingyitaro | 5:63f0d732f83c | 27 | FILE *wave_file; |
4180_1 | 4:79863d2ea5a0 | 28 | while(true) { // thread loop |
jingyitaro | 5:63f0d732f83c | 29 | |
jingyitaro | 5:63f0d732f83c | 30 | spk_mutex.lock(); |
jingyitaro | 5:63f0d732f83c | 31 | wave_file=fopen("/sd/sound01.wav","r"); |
jingyitaro | 5:63f0d732f83c | 32 | spk_mutex.unlock(); |
jingyitaro | 5:63f0d732f83c | 33 | |
jingyitaro | 5:63f0d732f83c | 34 | waver.play(wave_file); |
jingyitaro | 5:63f0d732f83c | 35 | |
jingyitaro | 5:63f0d732f83c | 36 | spk_mutex.lock(); |
jingyitaro | 5:63f0d732f83c | 37 | fclose(wave_file); |
jingyitaro | 5:63f0d732f83c | 38 | spk_mutex.unlock(); |
jingyitaro | 5:63f0d732f83c | 39 | |
jingyitaro | 5:63f0d732f83c | 40 | //Thread::wait(500); // wait |
4180_1 | 4:79863d2ea5a0 | 41 | } |
4180_1 | 4:79863d2ea5a0 | 42 | } |
jingyitaro | 5:63f0d732f83c | 43 | |
4180_1 | 4:79863d2ea5a0 | 44 | |
dreschpe | 0:f6a57b843f79 | 45 | int main() |
dreschpe | 0:f6a57b843f79 | 46 | { |
jingyitaro | 5:63f0d732f83c | 47 | |
4180_1 | 4:79863d2ea5a0 | 48 | Thread t6(thread6); //start thread6 |
jingyitaro | 5:63f0d732f83c | 49 | |
dreschpe | 2:a69c8c5f5b03 | 50 | while(true) { // main is the next thread |
jingyitaro | 5:63f0d732f83c | 51 | |
jingyitaro | 5:63f0d732f83c | 52 | //Thread::wait(1000); // wait 0.5s |
jingyitaro | 5:63f0d732f83c | 53 | |
jingyitaro | 5:63f0d732f83c | 54 | } |
jingyitaro | 5:63f0d732f83c | 55 | |
dreschpe | 0:f6a57b843f79 | 56 | } |