ECE 4180 Final

Dependencies:   mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem

Committer:
yqin70
Date:
Sun Dec 08 02:18:30 2019 +0000
Revision:
21:cbcbb3480cad
Parent:
19:d65f9fb1023b
somewhat done(pushbutton added, has an issue where if you spam the touchpad, it'll increase your score even if there is no bubble).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jcrane32 7:15fdc55dbf66 1 //class for 3 PWM color values for RGBLED
jcrane32 7:15fdc55dbf66 2 class LEDColor
jcrane32 7:15fdc55dbf66 3 {
jcrane32 7:15fdc55dbf66 4 public:
jcrane32 7:15fdc55dbf66 5 LEDColor(float r, float g, float b);
jcrane32 7:15fdc55dbf66 6 float red;
jcrane32 7:15fdc55dbf66 7 float green;
jcrane32 7:15fdc55dbf66 8 float blue;
jcrane32 7:15fdc55dbf66 9 };
jcrane32 7:15fdc55dbf66 10 LEDColor:: LEDColor(float r, float g, float b)
jcrane32 7:15fdc55dbf66 11 : red(r), green(g), blue(b)
jcrane32 7:15fdc55dbf66 12 {
jcrane32 7:15fdc55dbf66 13 }
jcrane32 7:15fdc55dbf66 14 //Operator overload to adjust brightness with no color change
jcrane32 7:15fdc55dbf66 15 LEDColor operator * (const LEDColor& x, const float& b)
jcrane32 7:15fdc55dbf66 16 {
jcrane32 7:15fdc55dbf66 17 return LEDColor(x.red*b,x.green*b,x.blue*b);
jcrane32 7:15fdc55dbf66 18 }
jcrane32 7:15fdc55dbf66 19 //Operator overload to add colors
jcrane32 7:15fdc55dbf66 20 LEDColor operator + (const LEDColor& x, const LEDColor& y)
jcrane32 7:15fdc55dbf66 21 {
jcrane32 7:15fdc55dbf66 22 return LEDColor(x.red+y.red,x.green+y.green,x.blue+y.blue);
jcrane32 7:15fdc55dbf66 23 }
jcrane32 7:15fdc55dbf66 24
jcrane32 7:15fdc55dbf66 25 //Class to control an RGB LED using three PWM pins
jcrane32 7:15fdc55dbf66 26
jcrane32 7:15fdc55dbf66 27 class RGBLed
jcrane32 7:15fdc55dbf66 28 {
jcrane32 7:15fdc55dbf66 29 public:
jcrane32 7:15fdc55dbf66 30 RGBLed(PinName redpin, PinName greenpin, PinName bluepin);
jcrane32 7:15fdc55dbf66 31 void write(float red,float green, float blue);
jcrane32 7:15fdc55dbf66 32 void write(LEDColor c);
jcrane32 7:15fdc55dbf66 33 RGBLed operator = (LEDColor c) {
jcrane32 7:15fdc55dbf66 34 write(c);
jcrane32 7:15fdc55dbf66 35 return *this;
jcrane32 7:15fdc55dbf66 36 };
jcrane32 7:15fdc55dbf66 37 private:
jcrane32 7:15fdc55dbf66 38 PwmOut _redpin;
jcrane32 7:15fdc55dbf66 39 PwmOut _greenpin;
jcrane32 7:15fdc55dbf66 40 PwmOut _bluepin;
jcrane32 7:15fdc55dbf66 41 };
jcrane32 7:15fdc55dbf66 42
jcrane32 7:15fdc55dbf66 43 RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin)
jcrane32 7:15fdc55dbf66 44 : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin)
jcrane32 7:15fdc55dbf66 45 {
jcrane32 7:15fdc55dbf66 46 //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker)
jcrane32 7:15fdc55dbf66 47 _redpin.period(0.0005);
jcrane32 7:15fdc55dbf66 48 }
jcrane32 7:15fdc55dbf66 49
jcrane32 7:15fdc55dbf66 50 void RGBLed::write(float red,float green, float blue)
jcrane32 7:15fdc55dbf66 51 {
jcrane32 7:15fdc55dbf66 52 _redpin = red;
jcrane32 7:15fdc55dbf66 53 _greenpin = green;
jcrane32 7:15fdc55dbf66 54 _bluepin = blue;
jcrane32 7:15fdc55dbf66 55 }
jcrane32 7:15fdc55dbf66 56 void RGBLed::write(LEDColor c)
jcrane32 7:15fdc55dbf66 57 {
jcrane32 7:15fdc55dbf66 58 _redpin = c.red;
jcrane32 7:15fdc55dbf66 59 _greenpin = c.green;
jcrane32 7:15fdc55dbf66 60 _bluepin = c.blue;
jcrane32 7:15fdc55dbf66 61 }
jcrane32 7:15fdc55dbf66 62
jcrane32 7:15fdc55dbf66 63 const LEDColor red(1.0,0.0,0.0);
jcrane32 19:d65f9fb1023b 64 const LEDColor orange(1.0,0.65,0.0);
jcrane32 7:15fdc55dbf66 65 const LEDColor green(0.0,0.2,0.0);
jcrane32 7:15fdc55dbf66 66 //brighter green LED is scaled down to same as red and
jcrane32 7:15fdc55dbf66 67 //blue LED outputs on Sparkfun RGBLED
jcrane32 7:15fdc55dbf66 68 const LEDColor blue(0.0,0.0,1.0);
jcrane32 7:15fdc55dbf66 69 const LEDColor yellow(1.0,0.2,0.0);
jcrane32 7:15fdc55dbf66 70 const LEDColor white(1.0,0.2,1.0);
jcrane32 7:15fdc55dbf66 71 const LEDColor black(0.0,0.0,0.0);