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: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player_appbd
main.cpp
- Committer:
- wschon
- Date:
- 2016-02-28
- Revision:
- 2:f4ad69c44c7e
- Parent:
- 1:2129bb91c172
- Child:
- 3:7d53a2744a2b
File content as of revision 2:f4ad69c44c7e:
#include "mbed.h"
#include "rtos.h"
#include "uLCD_4DGL.h"
#include "SDFileSystem.h"
#include "USBHostMSD.h"
#include "wave_player.h"
SDFileSystem sd(p5, p6, p7, p8, "sd");
Serial pc(USBTX, USBRX);
Mutex ulcd_mutex;
uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
DigitalOut myled(LED1);
//Analog Out Jack
AnalogOut DACout(p18);
//On Board Speaker
PwmOut PWMout(p21);
wave_player waver(&DACout,&PWMout);
int playing = 1;
void ulcd2_thread(void const *args) {
int count = 0;
while(true) {
ulcd_mutex.lock();
pc.printf("Activated mutex lock on uLCD screen: ulcd2_thread");
uLCD.cls();
uLCD.printf("\nECE 4180 L3: RTOS\n"); //Default Green on black text
uLCD.printf("\nWes Schon Nick Liu");
uLCD.printf("\n\nThread 2 count: %d", count);
if (playing == 1)
uLCD.printf("\n\nPlaying wav file...");
else
uLCD.printf("\n\nWav file finished.");
uLCD.text_width(4); //4X size text
uLCD.text_height(4);
Thread::wait(3000);
ulcd_mutex.unlock();
count++;
}
}
void wav_thread(void const *args) {
USBHostMSD msd("usb");
FILE *wave_file;
//setup PWM hardware for a Class D style audio output
PWMout.period(1.0/400000.0);
//printf("\n\n\nHello, wave world!\n");
// wait until connected to a USB device
while(!msd.connect()) {
Thread::wait(500);
}
//open wav file and play it
wave_file=fopen("/usb/sample.wav","r");
waver.play(wave_file);
fclose(wave_file);
//end of program
Thread::wait(500);
playing = 0;
}
void led_thread(void const *args) {
}
int main() {
Thread thread(ulcd2_thread);
Thread thread2(wav_thread);
int count2 = 0;
while(1) {
myled = 1;
Thread::wait(200);
myled = 0;
Thread::wait(200);
ulcd_mutex.lock();
uLCD.cls();
//SD card needed with image and video files for last two demos
uLCD.cls();
uLCD.media_init();
uLCD.printf("\n\nThread 1 count: %d", count2);
if (playing == 1)
uLCD.printf("\n\nPlaying wav file...");
else
uLCD.printf("\n\nWav file finished.");
Thread::wait(200);
uLCD.set_sector_address(0x0000, 0x0000);
uLCD.display_video(0,0);
Thread::wait(100);
ulcd_mutex.unlock();
count2++;
}
}
