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.
LEDMatrix.h
- Committer:
- EricWieser
- Date:
- 2012-02-13
- Revision:
- 0:1deae5ffe9ed
- Child:
- 1:44819562ea31
File content as of revision 0:1deae5ffe9ed:
#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); } } };