Eric Wieser / LEDMatrix
Revision:
0:1deae5ffe9ed
Child:
1:44819562ea31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDMatrix.h	Mon Feb 13 22:19:58 2012 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "Locations.h"
+#include "Matrix.h"
+
+template <int WIDTH, int HEIGHT> class LEDMatrix : public Matrix<bool> {
+  private:
+    DigitalOut*  _rows;
+    DigitalOut* _colClk;
+    DigitalOut* _colReset;
+    int _usPerColumn;
+    
+    //Column control
+    void firstColumn() {
+        *_colReset = 1;
+        wait_us(10);
+        *_colReset = 0;
+    }
+    void nextColumn() {
+        *_colClk = 1;
+        wait_us(10);
+        *_colClk = 0;
+    }
+    void showColumn(int c) {
+        bool* col = column(WIDTH - 1 - c);
+        for(int i = 0; i < HEIGHT; i++) {
+            _rows[i] = col[HEIGHT - 1 - i];
+        }
+        delete [] col;
+    }
+    void hideColumn(int c) {
+        for(int i = 0; i < HEIGHT; i++) {
+            _rows[i] = false;
+        }
+    }
+  public:
+    LEDMatrix(DigitalOut rows[HEIGHT], DigitalOut* colClk, DigitalOut* colReset, int usPerFrame) : 
+      Matrix<bool>(WIDTH, HEIGHT), _rows(rows), _colClk(colClk), _colReset(colReset) { 
+        clear();
+        firstColumn();
+        _usPerColumn = usPerFrame / WIDTH;
+    }
+    
+    void redraw() {
+        firstColumn();
+        for (int col = 0; col < WIDTH; col++) {
+            nextColumn();
+            showColumn(col);
+            wait_us(_usPerColumn);
+            hideColumn(col);
+        }
+    }
+};
\ No newline at end of file