A library to manipulate 2D arrays, and output them to an LED Dot Matrix Display. The display must be wired up using a shift register combined with a nor latch.

Committer:
EricWieser
Date:
Mon Feb 13 23:20:30 2012 +0000
Revision:
1:44819562ea31
Parent:
0:1deae5ffe9ed
Template ALL THE THINGS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricWieser 0:1deae5ffe9ed 1 #include "mbed.h"
EricWieser 0:1deae5ffe9ed 2 #include "Matrix.h"
EricWieser 0:1deae5ffe9ed 3
EricWieser 0:1deae5ffe9ed 4 template <int WIDTH, int HEIGHT> class LEDMatrix : public Matrix<bool> {
EricWieser 0:1deae5ffe9ed 5 private:
EricWieser 1:44819562ea31 6 //Array of row pins
EricWieser 1:44819562ea31 7 DigitalOut* _rows;
EricWieser 1:44819562ea31 8
EricWieser 1:44819562ea31 9 //Pointers to column control pins
EricWieser 1:44819562ea31 10 DigitalOut* _nextCol;
EricWieser 1:44819562ea31 11 DigitalOut* _firstCol;
EricWieser 0:1deae5ffe9ed 12 int _usPerColumn;
EricWieser 0:1deae5ffe9ed 13
EricWieser 0:1deae5ffe9ed 14 public:
EricWieser 1:44819562ea31 15 LEDMatrix(DigitalOut rows[HEIGHT], DigitalOut* nextCol, DigitalOut* firstCol, int usPerFrame) : Matrix<bool>(WIDTH, HEIGHT), _rows(rows), _nextCol(nextCol), _firstCol(firstCol) {
EricWieser 0:1deae5ffe9ed 16 clear();
EricWieser 0:1deae5ffe9ed 17 _usPerColumn = usPerFrame / WIDTH;
EricWieser 0:1deae5ffe9ed 18 }
EricWieser 0:1deae5ffe9ed 19
EricWieser 0:1deae5ffe9ed 20 void redraw() {
EricWieser 1:44819562ea31 21 //Pulse firstCol
EricWieser 1:44819562ea31 22 *_firstCol = 1;
EricWieser 1:44819562ea31 23 wait_us(10);
EricWieser 1:44819562ea31 24 *_firstCol = 0;
EricWieser 1:44819562ea31 25
EricWieser 1:44819562ea31 26 //Account for reverse column ordering
EricWieser 1:44819562ea31 27 for (int col = WIDTH - 1; col >= 0; col--) {
EricWieser 1:44819562ea31 28 //Pulse nextCol
EricWieser 1:44819562ea31 29 *_nextCol = 1;
EricWieser 1:44819562ea31 30 wait_us(10);
EricWieser 1:44819562ea31 31 *_nextCol = 0;
EricWieser 1:44819562ea31 32
EricWieser 1:44819562ea31 33 //Output a column of data to the row pins.
EricWieser 1:44819562ea31 34 for(int row = 0; row < HEIGHT; row++) {
EricWieser 1:44819562ea31 35 _rows[row] = (*this)(col, row);
EricWieser 1:44819562ea31 36 }
EricWieser 1:44819562ea31 37
EricWieser 1:44819562ea31 38 //Wait
EricWieser 0:1deae5ffe9ed 39 wait_us(_usPerColumn);
EricWieser 1:44819562ea31 40
EricWieser 1:44819562ea31 41 //Clear the column, ready for the next iteration
EricWieser 1:44819562ea31 42 for(int i = 0; i < HEIGHT; i++) {
EricWieser 1:44819562ea31 43 _rows[i] = false;
EricWieser 1:44819562ea31 44 }
EricWieser 0:1deae5ffe9ed 45 }
EricWieser 0:1deae5ffe9ed 46 }
EricWieser 0:1deae5ffe9ed 47 };