simple wrapper for the K64F RGB Led

Files at this revision

API Documentation at this revision

Comitter:
csjc99
Date:
Tue Feb 03 01:10:35 2015 +0000
Commit message:
initial version

Changed in this revision

KRGBLed.cpp Show annotated file Show diff for this revision Revisions of this file
KRGBLed.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ee2feb784400 KRGBLed.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KRGBLed.cpp	Tue Feb 03 01:10:35 2015 +0000
@@ -0,0 +1,19 @@
+#include "KRGBLed.h"
+
+KRGBLed::KRGBLed(PinName redPin, PinName greenPin, PinName bluePin) :
+    red(redPin),
+    green(greenPin),
+    blue(bluePin)
+{
+}
+
+KRGBLed::~KRGBLed()
+{
+}
+
+void KRGBLed::set(Color color)
+{
+    red = !(color & Red);
+    green = !(color & Green);
+    blue = !(color & Blue);
+}
\ No newline at end of file
diff -r 000000000000 -r ee2feb784400 KRGBLed.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KRGBLed.h	Tue Feb 03 01:10:35 2015 +0000
@@ -0,0 +1,34 @@
+
+#pragma once
+#include <mbed.h>
+
+/**
+ * K64F RGB LED example:
+ * KRGBLed rgb(LED_RED, LED_GREEN, LED_BLUE);
+ * rgb.set(KRGBLed::Magenta);
+ */
+class KRGBLed
+{
+public:
+    typedef enum
+    {
+        Off = 0,
+        Red = 1,
+        Green = 2,
+        Blue = 4,
+        Yellow = (Red|Green),
+        Cyan = (Green|Blue),  // @note more like a whiteish-blue
+        Magenta = (Blue|Red),
+        White = (Red|Green|Blue),
+    } Color;
+
+    KRGBLed(PinName redPin, PinName greenPin, PinName bluePin);
+    ~KRGBLed();
+
+    void set(Color color);
+
+private:
+    DigitalOut red;
+    DigitalOut green;
+    DigitalOut blue;
+};
\ No newline at end of file