Permalink
Browse files

support for 5 and 6 matrices

  • Loading branch information...
csquared committed May 29, 2013
1 parent d10f9a0 commit a27df6a48359f0f9e27060e7eee4b40649aeefa0
Showing with 67 additions and 31 deletions.
  1. +58 −26 HT1632.cpp
  2. +9 −5 HT1632.h
View
@@ -13,7 +13,7 @@ HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1) {
_height = 16;
}
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2) {
matrices = (HT1632 *)malloc(2 * sizeof(HT1632));
@@ -24,7 +24,7 @@ HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
_height = 16;
}
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2, uint8_t cs3) {
matrices = (HT1632 *)malloc(3 * sizeof(HT1632));
@@ -36,8 +36,8 @@ HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
_height = 16;
}
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2,
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2,
uint8_t cs3, uint8_t cs4) {
matrices = (HT1632 *)malloc(4 * sizeof(HT1632));
@@ -50,6 +50,38 @@ HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
_height = 16;
}
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2,
uint8_t cs3, uint8_t cs4,
uint8_t cs5) {
matrixNum = 5;
matrices = (HT1632 *)malloc(matrixNum * sizeof(HT1632));
matrices[0] = HT1632(data, wr, cs1);
matrices[1] = HT1632(data, wr, cs2);
matrices[2] = HT1632(data, wr, cs3);
matrices[3] = HT1632(data, wr, cs4);
matrices[4] = HT1632(data, wr, cs5);
_width = 24 * matrixNum;
_height = 16;
}
HT1632LEDMatrix::HT1632LEDMatrix(uint8_t data, uint8_t wr,
uint8_t cs1, uint8_t cs2,
uint8_t cs3, uint8_t cs4,
uint8_t cs5, uint8_t cs6) {
matrixNum = 6;
matrices = (HT1632 *)malloc(matrixNum * sizeof(HT1632));
matrices[0] = HT1632(data, wr, cs1);
matrices[1] = HT1632(data, wr, cs2);
matrices[2] = HT1632(data, wr, cs3);
matrices[3] = HT1632(data, wr, cs4);
matrices[4] = HT1632(data, wr, cs5);
matrices[5] = HT1632(data, wr, cs6);
_width = 24 * matrixNum;
_height = 16;
}
void HT1632LEDMatrix::setPixel(uint8_t x, uint8_t y) {
drawPixel(x, y, 1);
@@ -82,11 +114,11 @@ void HT1632LEDMatrix::drawPixel(uint8_t x, uint8_t y, uint8_t color) {
y *= 2;
} else {
y = (y-8) * 2 + 1;
}
}
i += y * 8;
if (color)
if (color)
matrices[m].setPixel(i);
else
matrices[m].clrPixel(i);
@@ -138,7 +170,7 @@ void HT1632LEDMatrix::writeScreen() {
}
// bresenham's algorithm - thx wikpedia
void HT1632LEDMatrix::drawLine(int8_t x0, int8_t y0, int8_t x1, int8_t y1,
void HT1632LEDMatrix::drawLine(int8_t x0, int8_t y0, int8_t x1, int8_t y1,
uint8_t color) {
uint16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
@@ -178,7 +210,7 @@ void HT1632LEDMatrix::drawLine(int8_t x0, int8_t y0, int8_t x1, int8_t y1,
}
// draw a rectangle
void HT1632LEDMatrix::drawRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
void HT1632LEDMatrix::drawRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
uint8_t color) {
drawLine(x, y, x+w-1, y, color);
drawLine(x, y+h-1, x+w-1, y+h-1, color);
@@ -188,7 +220,7 @@ void HT1632LEDMatrix::drawRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
}
// fill a rectangle
void HT1632LEDMatrix::fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
void HT1632LEDMatrix::fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
uint8_t color) {
for (uint8_t i=x; i<x+w; i++) {
for (uint8_t j=y; j<y+h; j++) {
@@ -200,7 +232,7 @@ void HT1632LEDMatrix::fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
// draw a circle outline
void HT1632LEDMatrix::drawCircle(uint8_t x0, uint8_t y0, uint8_t r,
void HT1632LEDMatrix::drawCircle(uint8_t x0, uint8_t y0, uint8_t r,
uint8_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
@@ -222,17 +254,17 @@ void HT1632LEDMatrix::drawCircle(uint8_t x0, uint8_t y0, uint8_t r,
x++;
ddF_x += 2;
f += ddF_x;
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 - x, y0 + y, color);
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 - x, y0 - y, color);
drawPixel(x0 + y, y0 + x, color);
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 + y, y0 - x, color);
drawPixel(x0 - y, y0 - x, color);
}
}
@@ -256,7 +288,7 @@ void HT1632LEDMatrix::fillCircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t colo
x++;
ddF_x += 2;
f += ddF_x;
drawLine(x0+x, y0-y, x0+x, y0+y+1, color);
drawLine(x0-x, y0-y, x0-x, y0+y+1, color);
drawLine(x0+y, y0-x, x0+y, y0+x+1, color);
@@ -265,7 +297,7 @@ void HT1632LEDMatrix::fillCircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t colo
}
void HT1632LEDMatrix::setCursor(uint8_t x, uint8_t y) {
cursor_x = x;
cursor_x = x;
cursor_y = y;
}
@@ -298,7 +330,7 @@ void HT1632LEDMatrix::write(uint8_t c) {
// draw a character
void HT1632LEDMatrix::drawChar(uint8_t x, uint8_t y, char c,
void HT1632LEDMatrix::drawChar(uint8_t x, uint8_t y, char c,
uint16_t color, uint8_t size) {
for (uint8_t i =0; i<5; i++ ) {
uint8_t line = pgm_read_byte(font+(c*5)+i);
@@ -308,15 +340,15 @@ void HT1632LEDMatrix::drawChar(uint8_t x, uint8_t y, char c,
drawPixel(x+i, y+j, color);
else { // big size
fillRect(x+i*size, y+j*size, size, size, color);
}
}
}
line >>= 1;
}
}
}
void HT1632LEDMatrix::drawBitmap(uint8_t x, uint8_t y,
void HT1632LEDMatrix::drawBitmap(uint8_t x, uint8_t y,
const uint8_t *bitmap, uint8_t w, uint8_t h,
uint8_t color) {
for (uint8_t j=0; j<h; j++) {
@@ -348,7 +380,7 @@ void HT1632::begin(uint8_t type) {
pinMode(_wr, OUTPUT);
digitalWrite(_wr, HIGH);
pinMode(_data, OUTPUT);
if (_rd >= 0) {
pinMode(_rd, OUTPUT);
digitalWrite(_rd, HIGH);
@@ -361,7 +393,7 @@ void HT1632::begin(uint8_t type) {
sendcommand(HT1632_INT_RC);
sendcommand(type);
sendcommand(HT1632_PWM_CONTROL | 0xF);
WIDTH = 24;
HEIGHT = 16;
}
@@ -372,18 +404,18 @@ void HT1632::setBrightness(uint8_t pwm) {
}
void HT1632::blink(boolean blinky) {
if (blinky)
if (blinky)
sendcommand(HT1632_BLINK_ON);
else
sendcommand(HT1632_BLINK_OFF);
}
void HT1632::setPixel(uint16_t i) {
ledmatrix[i/8] |= _BV(i%8);
ledmatrix[i/8] |= _BV(i%8);
}
void HT1632::clrPixel(uint16_t i) {
ledmatrix[i/8] &= ~_BV(i%8);
ledmatrix[i/8] &= ~_BV(i%8);
}
void HT1632::dumpScreen() {
@@ -452,7 +484,7 @@ void HT1632::writeRAM(uint8_t addr, uint8_t data) {
d |= addr & 0x7F;
d <<= 4;
d |= data & 0xF;
digitalWrite(_cs, LOW);
writedata(d, 14);
digitalWrite(_cs, HIGH);
@@ -465,10 +497,10 @@ void HT1632::sendcommand(uint8_t cmd) {
data <<= 8;
data |= cmd;
data <<= 1;
digitalWrite(_cs, LOW);
writedata(data, 12);
digitalWrite(_cs, HIGH);
digitalWrite(_cs, HIGH);
}
View
@@ -31,7 +31,7 @@ class HT1632 {
HT1632(int8_t data, int8_t wr, int8_t cs, int8_t rd = -1);
void begin(uint8_t type);
void clrPixel(uint16_t i);
void setPixel(uint16_t i);
@@ -42,7 +42,7 @@ class HT1632 {
void fillScreen();
void writeScreen();
void dumpScreen();
private:
int8_t WIDTH, HEIGHT;
int8_t _data, _cs, _wr, _rd;
@@ -56,10 +56,14 @@ class HT1632LEDMatrix : public Print {
public:
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1);
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1, uint8_t cs2);
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
uint8_t cs, uint8_t cs3);
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
uint8_t cs2, uint8_t cs3, uint8_t cs4);
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
uint8_t cs2, uint8_t cs3, uint8_t cs4, uint8_t cs5);
HT1632LEDMatrix(uint8_t data, uint8_t wr, uint8_t cs1,
uint8_t cs2, uint8_t cs3, uint8_t cs4, uint8_t cs5, uint8_t cs6);
void begin(uint8_t type);
void clearScreen(void);
@@ -91,7 +95,7 @@ class HT1632LEDMatrix : public Print {
#endif
void drawChar(uint8_t x, uint8_t y, char c, uint16_t color, uint8_t size);
void drawBitmap(uint8_t x, uint8_t y,
void drawBitmap(uint8_t x, uint8_t y,
const uint8_t *bitmap, uint8_t w, uint8_t h,
uint8_t color);

0 comments on commit a27df6a

Please sign in to comment.