ECE 4180 Lab 3 Part 3
Dependencies: 4DGL-uLCD-SE USBHost mbed wave_player_appbd
Fork of AppBoard_Waveplayer by
Revision 10:e008fb69af75, committed 2018-10-16
- Comitter:
- abraha2d
- Date:
- Tue Oct 16 00:25:09 2018 +0000
- Parent:
- 9:f1aebfbe7e78
- Commit message:
- Save point
Changed in this revision
4DGL-uLCD-SE.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f1aebfbe7e78 -r e008fb69af75 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Tue Oct 16 00:25:09 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r f1aebfbe7e78 -r e008fb69af75 main.cpp --- a/main.cpp Fri Nov 01 15:30:47 2013 +0000 +++ b/main.cpp Tue Oct 16 00:25:09 2018 +0000 @@ -1,21 +1,94 @@ #include "mbed.h" #include "USBHostMSD.h" #include "wave_player.h" -//mbed Application board waveplayer demo -//Plays the wave file "sample.wav" on the USB flash drive -//Outputs to onboard speaker (but at very low volume) -//and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume) -//Needs a USB flash drive inserted with the wav file on it to run +#include "uLCD_4DGL.h" -//Analog Out Jack AnalogOut DACout(p18); -//On Board Speaker PwmOut PWMout(p26); wave_player waver(&DACout,&PWMout); +PwmOut Rgb(p23); +PwmOut rGb(p24); +PwmOut rgB(p25); + +uLCD_4DGL uLCD(p9, p10, p11); // serial tx, serial rx, reset pin; + +Mutex uLCD_mutex; + +void thread1(void const *args) +{ + float x = 0.0; + while(1) { + //get a new random number for PWM + x = rand() / float(RAND_MAX); + //add some exponential brightness scaling + //for more of a fast flash effect + x = x*x*x; + Rgb = x; + rGb = x; + rgB = x; + //fast update rate for welding flashes + Thread::wait(20); + //add a random pause between welds + if (rand() / float(RAND_MAX) > 0.95) { + Rgb = 0; + rGb = 0; + rgB = 0; + Thread::wait(4000.0 * rand() / float(RAND_MAX)); + } + } + +} + +void thread2(void const *args) +{ + while(1) { + uLCD_mutex.lock(); + uLCD.locate(1,2); + uLCD.printf("Lightning!!!"); + uLCD_mutex.unlock(); + + Thread::wait(20); + + uLCD_mutex.lock(); + uLCD.locate(1,2); + uLCD.printf(" "); + uLCD_mutex.unlock(); + + if (rand() / float(RAND_MAX) > 0.95) { + Thread::wait(4000.0 * rand() / float(RAND_MAX)); + } + } +} + +void thread3(void const *args) +{ + while (1) { + uLCD_mutex.lock(); + uLCD.locate(1,5); + uLCD.printf("Thunder!!!"); + uLCD_mutex.unlock(); + + Thread::wait(20); + + uLCD_mutex.lock(); + uLCD.locate(1,5); + uLCD.printf(" "); + uLCD_mutex.unlock(); + + if (rand() / float(RAND_MAX) > 0.95) { + Thread::wait(4000.0 * rand() / float(RAND_MAX)); + } + } +} + int main() { + Thread t1(thread1); + Thread t2(thread2); + Thread t3(thread3); + USBHostMSD msd("usb"); FILE *wave_file; //setup PWM hardware for a Class D style audio output @@ -25,10 +98,11 @@ 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 - while(1) {}; + while (1) { + //open wav file and play it + wave_file=fopen("/usb/storm-thunder.wav","r"); + waver.play(wave_file); + fclose(wave_file); + Thread::wait(4000.0 * rand() / float(RAND_MAX)); + } } \ No newline at end of file