ECE 4180 Final
Dependencies: mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem
Revision 7:15fdc55dbf66, committed 2019-12-05
- Comitter:
- jcrane32
- Date:
- Thu Dec 05 03:21:55 2019 +0000
- Parent:
- 6:cd24147b5e50
- Child:
- 8:2451a896f22a
- Child:
- 18:c760ba93b881
- Commit message:
- Further tidied up code base. Set up templates for c arrays for songs and ticker to play music from arrays.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LED.hpp Thu Dec 05 03:21:55 2019 +0000 @@ -0,0 +1,70 @@ +//class for 3 PWM color values for RGBLED +class LEDColor +{ +public: + LEDColor(float r, float g, float b); + float red; + float green; + float blue; +}; +LEDColor:: LEDColor(float r, float g, float b) + : red(r), green(g), blue(b) +{ +} +//Operator overload to adjust brightness with no color change +LEDColor operator * (const LEDColor& x, const float& b) +{ + return LEDColor(x.red*b,x.green*b,x.blue*b); +} +//Operator overload to add colors +LEDColor operator + (const LEDColor& x, const LEDColor& y) +{ + return LEDColor(x.red+y.red,x.green+y.green,x.blue+y.blue); +} + +//Class to control an RGB LED using three PWM pins + +class RGBLed +{ +public: + RGBLed(PinName redpin, PinName greenpin, PinName bluepin); + void write(float red,float green, float blue); + void write(LEDColor c); + RGBLed operator = (LEDColor c) { + write(c); + return *this; + }; +private: + PwmOut _redpin; + PwmOut _greenpin; + PwmOut _bluepin; +}; + +RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin) + : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin) +{ + //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker) + _redpin.period(0.0005); +} + +void RGBLed::write(float red,float green, float blue) +{ + _redpin = red; + _greenpin = green; + _bluepin = blue; +} +void RGBLed::write(LEDColor c) +{ + _redpin = c.red; + _greenpin = c.green; + _bluepin = c.blue; +} + +const LEDColor red(1.0,0.0,0.0); +const LEDColor green(0.0,0.2,0.0); +//brighter green LED is scaled down to same as red and +//blue LED outputs on Sparkfun RGBLED +const LEDColor blue(0.0,0.0,1.0); +const LEDColor yellow(1.0,0.2,0.0); +const LEDColor white(1.0,0.2,1.0); +const LEDColor black(0.0,0.0,0.0); \ No newline at end of file
--- a/main.cpp Thu Dec 05 00:17:49 2019 +0000 +++ b/main.cpp Thu Dec 05 03:21:55 2019 +0000 @@ -1,11 +1,11 @@ #include "mbed.h" +#include "rtos.h" #include "SDFileSystem.h" #include "wave_player.h" #include "uLCD_4DGL.h" //setup some color objects in flash using const's -#include "rtos.h" #include "Small_6.h" #include "Small_7.h" #include "Arial_9.h" @@ -14,80 +14,12 @@ #include "bubbles.h" #include "songs.h" +#include "LED.hpp" -//class for 3 PWM color values for RGBLED -class LEDColor -{ -public: - LEDColor(float r, float g, float b); - float red; - float green; - float blue; -}; -LEDColor:: LEDColor(float r, float g, float b) - : red(r), green(g), blue(b) -{ -} -//Operator overload to adjust brightness with no color change -LEDColor operator * (const LEDColor& x, const float& b) -{ - return LEDColor(x.red*b,x.green*b,x.blue*b); -} -//Operator overload to add colors -LEDColor operator + (const LEDColor& x, const LEDColor& y) -{ - return LEDColor(x.red+y.red,x.green+y.green,x.blue+y.blue); -} - -//Class to control an RGB LED using three PWM pins -class RGBLed -{ -public: - RGBLed(PinName redpin, PinName greenpin, PinName bluepin); - void write(float red,float green, float blue); - void write(LEDColor c); - RGBLed operator = (LEDColor c) { - write(c); - return *this; - }; -private: - PwmOut _redpin; - PwmOut _greenpin; - PwmOut _bluepin; -}; - -RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin) - : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin) -{ - //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker) - _redpin.period(0.0005); -} - -void RGBLed::write(float red,float green, float blue) -{ - _redpin = red; - _greenpin = green; - _bluepin = blue; -} -void RGBLed::write(LEDColor c) -{ - _redpin = c.red; - _greenpin = c.green; - _bluepin = c.blue; -} - -//classes could be moved to include file //Setup RGB led using PWM pins and class RGBLed myRGBled(p24,p23,p22); //RGB PWM pins -const LEDColor red(1.0,0.0,0.0); -const LEDColor green(0.0,0.2,0.0); -//brighter green LED is scaled down to same as red and -//blue LED outputs on Sparkfun RGBLED -const LEDColor blue(0.0,0.0,1.0); -const LEDColor yellow(1.0,0.2,0.0); -const LEDColor white(1.0,0.2,1.0); -const LEDColor black(0.0,0.0,0.0); + char bred=0; char bgreen=0; char bblue=0; @@ -95,7 +27,8 @@ volatile bool songselect = false; volatile bool homescreen = true; volatile bool songchange = false; -uLCD_4DGL uLCD(p28,p27,p30); +volatile bool playing = false; +uLCD_4DGL uLCD(p28,p27,p30); SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card DigitalOut myled(LED1); DigitalIn pb1(p20); @@ -103,6 +36,8 @@ AnalogOut DACout(p18); wave_player waver(&DACout); Thread thread1, thread2, thread3; +Ticker nextsample; +int songNdx = 0; // mutex to make the lcd lib thread safe Mutex lcd_mutex; @@ -126,7 +61,7 @@ uLCD.locate(4,1); uLCD.printf("Revolution"); uLCD.locate(0,3); - uLCD.printf("Pick a song"); + uLCD.printf("Pick a song!"); uLCD.text_height(1.3); uLCD.text_width(1.9); uLCD.locate(3,5); @@ -136,7 +71,7 @@ uLCD.locate(3,9); uLCD.printf("Stacy's Mom"); uLCD.locate(3,11); - uLCD.printf("I Write Sins \n \t Not Tragedies"); + uLCD.printf("I Write Sins \n \t Not Tragedies"); uLCD.filled_circle(6, 43, 4, GREEN); //new selection with circle instead of rectangle homescreen = false;} if (songchange){ @@ -152,8 +87,7 @@ } // Thread 2 -//for song selection during homescreen - +// joystick control for song selection during homescreen void joystick_thread() { while(1){ @@ -190,17 +124,25 @@ } } -int main() -{ - //timestamp in terms of seconds +// Thread 4 +// this thread plays music using the ticker class +void playsound() { + if (playing) { + //DACout = song[songNdx++]; + //if (i>**songlength**) i + } else { + DACout = 0; + songNdx = 0; + } +} + +int main() { - //doesnt work yet, nee,d to ask hamblen - uLCD.media_init(); - uLCD.set_sector_address(0x001D, 0x4C01); - uLCD.display_image(0,0); + uLCD.baudrate(3000000); thread1.start(homescreen_thread); - thread2.start(joystick_thread); + thread2.start(joystick_thread); thread3.start(pbcontrol_thread); +// nextsample.attach(&playsound, 1.0/8000.0); //startup sound myRGBled = blue; //tested to make sure led works, we can use whatever color(s) here FILE *wave_file;
--- a/songs.h Thu Dec 05 00:17:49 2019 +0000 +++ b/songs.h Thu Dec 05 03:21:55 2019 +0000 @@ -1,4 +1,4 @@ //const unsigned short the_middle[]; //const unsigned short stacys_mom[]; //const unsigned short sins[]; -//const unsigned short fireflies[]; \ No newline at end of file +//const unsigned short fireflies[];