ST7565 question

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
bleudeciel16
 
Posts: 12
Joined: Sun Jul 01, 2012 2:10 pm

ST7565 question

Post by bleudeciel16 »

I broke out my ST7565 and hooked it up for a project I'm working on. I've tested it and it works great, but today, I wanted to do a custom UI. The problem I'm having is that the drawstring() function uses line numbers instead of Y coordinates. I wanted a title at the top, then a line across the screen below it to set it apart from the text on the rest of the screen. This line ended up being along the top pixels of the second row of text, which is bad. Since it uses line numbers instead of Y coordinates, I have no way to move the second line of text down by 2 pixels.

I'm somewhat knowledgeable at programming, but my brain goes numb trying to read someone else's code. I attempted to update it to use y coordinates but couldn't get anything to work right so I gave up.

Is there a way to change it to use Y coordinates instead of line numbers? I was surprised to see line numbers instead of Y coordinates since it would give you more versatility, while still being able to go down line by line if you wanted (y+8).

I found a couple other libraries for this display but couldn't get one working and the other was a little to feature rich for my needs. HALP!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: ST7565 question

Post by adafruit_support_rick »

Hmmm. I don't have anything to test this on just now, but I can speculate on what might work. The simplest thing might be to add a "bias" argument to drawstring and drawchar. The bias is effectively a fractional line number, allowing you to more-or-less treat 'line' as an 11-bit fixed-point number.

Code: Select all

void ST7565::drawstring(uint8_t x, uint8_t line, char *c, uint8_t linebias) {
  linebias &= 0x07;   //range-limit to 0..7
  while (c[0] != 0) {
    drawchar(x, line, c[0], linebias);
    c++;
    x += 6; // 6 pixels wide
    if (x + 6 >= LCDWIDTH) {
      x = 0;    // ran out of this line
      line++;
    }
    if (line >= (LCDHEIGHT/8))
      return;        // ran out of space :(
  }
}


void ST7565::drawstring_P(uint8_t x, uint8_t line, const char *str, uint8_t linebias) {
  linebias &= 0x07;   //range-limit to 0..7
  while (1) {
    char c = pgm_read_byte(str++);
    if (! c)
      return;
    drawchar(x, line, c, linebias);
    x += 6; // 6 pixels wide
    if (x + 6 >= LCDWIDTH) {
      x = 0;    // ran out of this line
      line++;
    }
    if (line >= (LCDHEIGHT/8))
      return;        // ran out of space :(
  }
}

void  ST7565::drawchar(uint8_t x, uint8_t line, char c, uint8_t linebias) {
  for (uint8_t i =0; i<5; i++ ) {
    st7565_buffer[x + (line*128) + (linebias * 16) ] = pgm_read_byte(font+(c*5)+i);  //fixed-point multiply of (128 * line.linebias)
    x++;
  }

  updateBoundingBox(x, line*8, x+5, line*8 + 8);
}
If you make linebias an optional argument, you'll retain backwards-compatibility:

Code: Select all

void drawchar(uint8_t x, uint8_t line, char c, uint8_t linebias = 0);
  void drawstring(uint8_t x, uint8_t line, char *c, uint8_t linebias = 0);
  void drawstring_P(uint8_t x, uint8_t line, const char *c, uint8_t linebias = 0);
For your two-line offset, you would call drawstring just as you do now, and give it a linebias of 2.

No guarantees!!! I'm just typing code into a reply box. I haven't tested it at all. And I didn't try to handle the overrun case of a non-zero linebias on the last line of the display. I'll leave that as an exercise for the reader.

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

Return to “Arduino”