Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: LEDMatrix.h
- Revision:
- 1:44819562ea31
- Parent:
- 0:1deae5ffe9ed
diff -r 1deae5ffe9ed -r 44819562ea31 LEDMatrix.h
--- a/LEDMatrix.h Mon Feb 13 22:19:58 2012 +0000
+++ b/LEDMatrix.h Mon Feb 13 23:20:30 2012 +0000
@@ -1,52 +1,47 @@
#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;
+ //Array of row pins
+ DigitalOut* _rows;
+
+ //Pointers to column control pins
+ DigitalOut* _nextCol;
+ DigitalOut* _firstCol;
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) {
+ LEDMatrix(DigitalOut rows[HEIGHT], DigitalOut* nextCol, DigitalOut* firstCol, int usPerFrame) : Matrix<bool>(WIDTH, HEIGHT), _rows(rows), _nextCol(nextCol), _firstCol(firstCol) {
clear();
- firstColumn();
_usPerColumn = usPerFrame / WIDTH;
}
void redraw() {
- firstColumn();
- for (int col = 0; col < WIDTH; col++) {
- nextColumn();
- showColumn(col);
+ //Pulse firstCol
+ *_firstCol = 1;
+ wait_us(10);
+ *_firstCol = 0;
+
+ //Account for reverse column ordering
+ for (int col = WIDTH - 1; col >= 0; col--) {
+ //Pulse nextCol
+ *_nextCol = 1;
+ wait_us(10);
+ *_nextCol = 0;
+
+ //Output a column of data to the row pins.
+ for(int row = 0; row < HEIGHT; row++) {
+ _rows[row] = (*this)(col, row);
+ }
+
+ //Wait
wait_us(_usPerColumn);
- hideColumn(col);
+
+ //Clear the column, ready for the next iteration
+ for(int i = 0; i < HEIGHT; i++) {
+ _rows[i] = false;
+ }
}
}
};
\ No newline at end of file