k

Dependents:   4180Lab3Part2Bluetooth

Files at this revision

API Documentation at this revision

Comitter:
elirobelo
Date:
Thu Feb 23 22:41:52 2017 +0000
Commit message:
rgb;

Changed in this revision

rgb-led.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ecca218c906a rgb-led.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgb-led.h	Thu Feb 23 22:41:52 2017 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+//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);
+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;
+}
\ No newline at end of file