Library for Sure Electronics HT1632 based LED matrix displays. Supports multiple displays connected together.
Dependents: HT1632MsgScroller SMS_LEDMatrixPrinter
Diff: HT1632_LedMatrix.cpp
- Revision:
- 14:b051965066db
- Parent:
- 13:9a869360d0ae
- Child:
- 15:9323fab1db01
--- a/HT1632_LedMatrix.cpp Mon Apr 08 20:54:20 2013 +0000 +++ b/HT1632_LedMatrix.cpp Mon Jul 29 21:10:07 2013 +0000 @@ -53,17 +53,12 @@ * For mbed, use WR=p7, DATA=p5, cs1=p17, cs2=p18, cs3=p19, cs4=p20 */ -DigitalOut ht1632_wrclk(p7); -DigitalOut ht1632_data(p5); -DigitalOut ht1632_cs1(p17); -DigitalOut ht1632_cs2(p18); -DigitalOut ht1632_cs3(p19); -DigitalOut ht1632_cs4(p20); - // CS pins 17, 18, 19, 20 used. -//DigitalOut ht1632_cs[4] = {p17, p18, p19, p20}; // Chip Select (1, 2, 3, 4) -//DigitalOut ht1632_cs[4] = {p19, p18, p20, p17}; // Chip Select (1, 2, 3, 4) -DigitalOut ht1632_cs[4] = {p19, p17, p18, p20}; // Chip Select (1, 2, 3, 4) +// Stripboard +//DigitalOut _cs[4] = {p17, p18, p19, p20}; // Chip Select (1, 2, 3, 4) +// PCB +DigitalOut *_cs[4]; // = { NC,NC,NC,NC}; //= { +//p19, p17, p18, p20}; // Chip Select (1, 2, 3, 4) // helper macros #define chip_number(x,y) (x >> 5) + (y >> 3)*numYDevices @@ -107,14 +102,21 @@ }; -// Default constructor -HT1632_LedMatrix::HT1632_LedMatrix( void ) +// Default constructor p19, p17, p18, p20 +//HT1632_LedMatrix::HT1632_LedMatrix( void ) { } + +HT1632_LedMatrix::HT1632_LedMatrix( PinName _clk, PinName _dat, PinName cs1, PinName cs2, PinName cs3, PinName cs4 ) : + _wrclk(_clk), _data(_dat), _cs1(cs1), _cs2(cs2), _cs3(cs3), _cs4(cs4) { + _cs[0] = &_cs1; + _cs[1] = &_cs2; + _cs[2] = &_cs3; + _cs[3] = &_cs4; } - void HT1632_LedMatrix::init( uint8_t xDevices, uint8_t yDevices, uint8_t displayType ) { + // Set up the display size based on number of devices both horizontal and vertical numXDevices = xDevices; @@ -133,7 +135,11 @@ // Disable all display CS lines by taking high for( uint8_t i = 0; i < 4; i++ ) - ht1632_cs[i] = HIGH; + _cs[i] = HIGH; +// _cs1 = HIGH; +// _cs2 = HIGH; +// _cs3 = HIGH; +// _cs4 = HIGH; for (uint8_t chipno=0; chipno<4; chipno++) { chipfree(chipno); // unselect it @@ -157,6 +163,7 @@ } cursorX = 0; cursorY = 0; + } void HT1632_LedMatrix::displayOff( void ) @@ -184,14 +191,12 @@ ***********************************************************************/ void HT1632_LedMatrix::chipselect(uint8_t chipno) { -// for(int i=0; i<4; i++) - ht1632_cs[chipno] = LOW; + *_cs[chipno] = LOW; } void HT1632_LedMatrix::chipfree(uint8_t chipno) { -// for(int i=0; i<4; i++) - ht1632_cs[chipno] = HIGH; + *_cs[chipno] = HIGH; } /** @@ -204,13 +209,14 @@ void HT1632_LedMatrix::writebits (uint8_t bits, uint8_t firstbit) { while (firstbit) { - ht1632_wrclk = LOW; + _wrclk = LOW; +// for( int i=0; i<2; i++); if (bits & firstbit) { - ht1632_data = HIGH; + _data = HIGH; } else { - ht1632_data = LOW; + _data = LOW; } - ht1632_wrclk = HIGH; + _wrclk = HIGH; firstbit >>= 1; } } @@ -224,9 +230,10 @@ void HT1632_LedMatrix::writedatabits (uint8_t bits, uint8_t count) { while (count) { - ht1632_wrclk = LOW; - ht1632_data = bits & 1; - ht1632_wrclk = HIGH; + _wrclk = LOW; +// for( int i=0; i<2; i++); + _data = bits & 1; + _wrclk = HIGH; count--; bits >>= 1; } @@ -408,24 +415,26 @@ return colsLeft; } -int HT1632_LedMatrix::_putc(int c) { - if (c == '\n') { - cursorY += 8; - cursorX = 0; - } else if (c == '\r') { - // skip em - } else { - putChar(cursorX, cursorY, c); - cursorX += 6; +int HT1632_LedMatrix::_putc(int c) +{ + if (c == '\n') { + cursorY += 8; + cursorX = 0; + } else if (c == '\r') { + // skip em + } else { + putChar(cursorX, cursorY, c); + cursorX += 6; // if (wrap && (cursorX > (_width - 6))) { // cursorY += 8; // cursorX = 0; // } - } + } - return c; + return c; } -int HT1632_LedMatrix::_getc() { +int HT1632_LedMatrix::_getc() +{ return -1; }