HT1632 library documentation

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
tonystark622
 
Posts: 5
Joined: Thu Feb 21, 2013 3:21 am

HT1632 library documentation

Post by tonystark622 »

Hi folks, I'm a newbie here, so be gentle. I did search the forums first.

I just purchased the 16x24 Red LED Matrix, hooked it to an Arduino UNO and ran the example programs. Once I soldered the J5 jumper, everything has been working. Thanks for the excellent reference and pictures.

On to my questions. I am a programmer by trade, although new to the Arduino. Is there any documenation on the HT1632 library and various objects and methods(functions)?

I have a basic scrolling text demo working, but I'm not convinced that I am using the most efficient way to do this... or necessarily all the right methods/functions.

Here's my current code:

Code: Select all

#include "HT1632.h"

#define DATA 2
#define WR   3
#define CS   4
#define CS2  5

// use this line for single matrix
HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS);
// use this line for two matrices!
//HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS, CS2);

void setup() {
  Serial.begin(9600);
  matrix.begin(HT1632_COMMON_16NMOS);  
  matrix.fillScreen();
  delay(500);

}

void loop() {
  int x=0;
   
  
  matrix.clearScreen(); 
  // draw some text!
  matrix.setTextSize(1);    // size 1 == 8 pixels high
  matrix.setTextColor(1);   // 'lit' LEDs

  
  for (x = 23; x > -60;x--){
  matrix.setCursor(x, 8);   // next line, 8 pixels down
  matrix.print("Jane Ellen");
  matrix.writeScreen();
  delay(50);
  matrix.clearScreen();
  }
  // whew!
}
Is the matrix.clearScreen() call within the loop the best way of clearing the screen before repositioning the text? Is this the way to produce the smoothest scrolling?

Any suggestions would be appreciated.
Thanks,
Tony Stark

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: HT1632 library documentation

Post by adafruit_support_bill »

The definitive reference is the source code. It is not hard to follow - especially if you are a programmer.
https://github.com/adafruit/HT1632

Clearscreen is probably the best method in the library for what you want. You might be able to implement a smoother scrolling function with direct manipulation of the buffer.

tonystark622
 
Posts: 5
Joined: Thu Feb 21, 2013 3:21 am

Re: HT1632 library documentation

Post by tonystark622 »

I'm having trouble figuring something out. If anyone knows the answer, I'd appreciate the help.

In my scrolling text demo, it works for setTextSize(1), but when I change it to setTextSize(2), the text disappears when the x position < -1 (or 0).
Here's the code:

Code: Select all

#include "HT1632.h"

#define DATA 2
#define WR   3
#define CS   4
#define CS2  5

// use this line for single matrix
HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS);
// use this line for two matrices!
//HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS, CS2);

void setup() {
  Serial.begin(9600);
  matrix.begin(HT1632_COMMON_16NMOS);  
}

void loop() {
  int x=0;
  char displayString [] = "Sample String";
  int stringLength = sizeof(displayString) - 1;
  int lowerLeftLimit = stringLength * 6 * -1;
  int displayWidth = matrix.width() - 1;
  int topX;
  
  matrix.clearScreen(); 
  matrix.setTextSize(1);    // this works
//  matrix.setTextSize(2);  //this fails when x < -1
                          // text just disappears
  matrix.setTextColor(1);   // 'lit' LEDs
  
  for (x = displayWidth; x > (lowerLeftLimit);x--){
    if (x >= lowerLeftLimit) {
      matrix.setCursor(x, 0);   // next line, 8 pixels down
      matrix.print(displayString);
    }
    matrix.writeScreen();
    delay(50);
    matrix.clearScreen();
  }
  // whew!
}
Any thoughts?

Also, I looked for code to use 2 buffers but I didn't see anything in this library. Is there a different library that I should use?

I appreciate all the help I can get with this.

Thanks,
Tony Stark

odometer
 
Posts: 98
Joined: Sun Aug 21, 2011 11:01 pm

Re: HT1632 library documentation

Post by odometer »

I wanted to make a "demo" for a digital clock, so I modified one of the library functions like this:

Code: Select all

// draw a character
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);
    for (uint8_t j = 0; j<8; j++) {
      if (true) {
	if (size == 1) // default size
	  drawPixel(x+i, y+j, ((line&0x1)?color:0));
	else {  // big size
	  fillRect(x+i*size, y+j*size, size, size, ((line&0x1)?color:0));
	} 
      }
      line >>= 1;
    }
  }
}
This makes it draw the dark cells as well as the bright cells.

My guess is you want this:

Code: Select all

// draw a character
void HT1632LEDMatrix::drawChar(uint8_t x, uint8_t y, char c, 
			      uint16_t color, uint8_t size) {
  for (uint8_t i =0; i<6; i++ ) {
    uint8_t line = 0;
    if (i<5) line = pgm_read_byte(font+(c*5)+i);
    for (uint8_t j = 0; j<8; j++) {
      if (true) {
	if (size == 1) // default size
	  drawPixel(x+i, y+j, ((line&0x1)?color:0));
	else {  // big size
	  fillRect(x+i*size, y+j*size, size, size, ((line&0x1)?color:0));
	} 
      }
      line >>= 1;
    }
  }
}
This way, you get a 1-pixel-wide "space" to the right of each character.

tonystark622
 
Posts: 5
Joined: Thu Feb 21, 2013 3:21 am

Re: HT1632 library documentation

Post by tonystark622 »

Thanks for the response. I'll try it sometime in the middle of the week when I get back home.

Tony

tonystark622
 
Posts: 5
Joined: Thu Feb 21, 2013 3:21 am

Re: HT1632 library documentation

Post by tonystark622 »

That didn't help... But, I did get it fixed.

The problem turned out to be that the fillRectangle routine defines x as an unsigned 8 bit integer. This apparently (I know, duh!) doesn't handle x coordinates less than zero the way I expected. Changing the argument in the function and function prototype fixed my problem. 16 bit high characters scroll just like the 8 bit high characters now.

Hope that helps someone.
Tony

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: HT1632 library documentation

Post by adafruit_support_bill »

Good to know! Thanks for the follow up. :)

samir
 
Posts: 1
Joined: Mon May 13, 2013 1:27 am

Re: HT1632 library documentation

Post by samir »

Hello,

I think I am having the same problem as Tony, I am able to get the 8-bit text to scroll but am unable to get the 16-bit text to scroll, he said he changed the 'function and function prototype' but I am unsure as to what that means and how he changed it. Any help would be appreciated.

Thank You

pinballex
 
Posts: 2
Joined: Sun Jun 23, 2013 11:25 am

Re: HT1632 library documentation

Post by pinballex »

Hi,

I also have the same problem, does the solution as discribed by Tony mean that I have to alter this in the liberyfile?
and is this the .h file or the .ccp file or both.

can anyone explain how to do that,
thanks in advance for the help,

Lex

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: HT1632 library documentation

Post by adafruit_support_bill »

To implement Tony's solution, you need to modify the .cpp file in the library. He has posted his code above. Find the existing functions with the same names and replace them with the ones he has posted.

tonystark622
 
Posts: 5
Joined: Thu Feb 21, 2013 3:21 am

Re: HT1632 library documentation

Post by tonystark622 »

For those of you that need to see the code...
Here is the code for the HT1632.h file

Code: Select all

  void fillRect(int8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color);
Here is the whole fillRect routine from the HT1632.cpp file:

Code: Select all

// fill a rectangle
void HT1632LEDMatrix::fillRect(int8_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++) {
      drawPixel(i, j, color);
    }
  }
}
NOTE: I only changed the first argument from "uint8_t x" to "int8_t x". I'm not sure that int8_t is the best data type as I'm not up on the data types available in this compiler... for instance, what's the highest positive or negative number that an int8_t variable can hold? You may want to consider this as you make these changes to the HT1632.h and HT1632.cpp files.

Hope this helps,
Tony

pinballex
 
Posts: 2
Joined: Sun Jun 23, 2013 11:25 am

Re: HT1632 library documentation

Post by pinballex »

Hi Tony,

the scrolling of the large textformat works for me too now.
thanks for sharing!

Lex

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”