Two simple classes for using the RGB led

Dependencies:   mbed

Dependents:   4180-lab3-RTOS 4180-FinalProject

Files at this revision

API Documentation at this revision

Comitter:
kswanson31
Date:
Mon Oct 10 00:32:31 2016 +0000
Child:
1:0008e30a2bda
Commit message:
Two simple classes for using RGB led

Changed in this revision

SimpleRGB.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleRGB.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleRGB.cpp	Mon Oct 10 00:32:31 2016 +0000
@@ -0,0 +1,36 @@
+#include "SimpleRGB.h"
+
+
+// construct a LightColor object
+LightColor::LightColor(float r, float g, float b)
+    : red(r), green(g), blue(b)
+{
+}
+
+// construct an RGBLed object
+RGBLed::RGBLed(PinName rpin, PinName gpin, PinName bpin)
+    : _rpin(rpin), _gpin(gpin), _bpin(bpin)
+{
+    //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker)
+    _rpin.period(0.0005);
+}
+
+// write directly to an RGBLed object
+void RGBLed::write(float red, float green, float blue) {
+    _rpin = red;
+    _gpin = green;
+    _bpin = blue;
+}
+
+// use a LightColor object to change the RGBLed
+void RGBLed::write(LightColor color) {
+    _rpin = color.red;
+    _gpin = color.green;
+    _bpin = color.blue;
+}
+
+// alow assingment of LightColor object to the RGBLed object
+RGBLed operator = (LightColor color) {
+    write(color);
+    return *this;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleRGB.h	Mon Oct 10 00:32:31 2016 +0000
@@ -0,0 +1,31 @@
+#ifndef SIMPLERGB_H
+#define SIMPLERGB_H
+
+#include "mbed.h"
+
+class LightColor
+{
+    public:
+        LightColor(float r, float g, float b);
+        float red;
+        float green;
+        float blue;
+};
+
+class RGBLed
+{
+    public:
+        RGBLed(PinName rpin, PinName gpin, PinName bpin);
+        void write(float red, float green, float blue);
+        void write(LightColor color);
+        
+    private:
+        PwmOut _rpin;
+        PwmOut _gpin;
+        PwmOut _bpin;
+};
+
+#endif
+    
+        
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 10 00:32:31 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file