Control the BlinkM LED Module via I2C.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cody
Date:
Thu Jun 28 19:35:57 2012 +0000
Commit message:

Changed in this revision

blinkm.cpp Show annotated file Show diff for this revision Revisions of this file
blinkm.h Show annotated file Show diff for this revision Revisions of this file
main.cpp 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
diff -r 000000000000 -r 97cacd0a950a blinkm.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blinkm.cpp	Thu Jun 28 19:35:57 2012 +0000
@@ -0,0 +1,22 @@
+#include "blinkm.h"
+
+BlinkM::BlinkM(I2C &_i2c, char _adress) : i2c(_i2c), adress(_adress)
+{
+}
+
+bool BlinkM::StopScript()
+{
+    return i2c.write(adress, "o", 1) == 0;
+}
+
+bool BlinkM::PlayScript(char number, char repeats)
+{
+    char data[4] = {'p', number, repeats, 0};
+    return i2c.write(adress, data, 4) == 0;
+}
+
+bool BlinkM::Fade(char r, char g, char b)
+{
+    char data[4] = {'c', r, g, b};
+    return i2c.write(adress, data, 4) == 0;
+}
diff -r 000000000000 -r 97cacd0a950a blinkm.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blinkm.h	Thu Jun 28 19:35:57 2012 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+
+class BlinkM
+{
+public:
+    BlinkM(I2C &_i2c, char _adress);
+    bool StopScript();
+    bool PlayScript(char number, char repeats);
+    bool Fade(char r, char g, char b);
+protected:
+    I2C &i2c;
+    char adress;
+};
diff -r 000000000000 -r 97cacd0a950a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 28 19:35:57 2012 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+#include "blinkm.h"
+
+I2C i2c (p28,p27);
+BlinkM blinkm(i2c, 0x12);
+
+int main()
+{
+    //blinkm.StopScript();
+    //blinkm.Fade(0x00, 0xFF, 0x00);
+    
+    blinkm.PlayScript(1,0);
+    
+    while(1)
+    {
+    }
+}
diff -r 000000000000 -r 97cacd0a950a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 28 19:35:57 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479