Skip to content

displayText optimization #3

@JezausTevas

Description

@JezausTevas

Current version of displayText function:

void TM1638lite::displayText(String text) {
  uint8_t length = text.length();

  for (uint8_t i = 0; i < length; i++) {
    for (uint8_t position = 0; position < 8; position++) {
      displayASCII(position, text[position]);
    }
  }
}

Has unnecessary for loop and can be reduced to:

void TM1638lite::displayText(String text) {
  uint8_t length = text.length();
  for (uint8_t position = 0; position < 8 && position < length; position++)
	displayASCII(position, text[position]);
}

As of my own testing this change have reduced function execution time by 22millis (from 25millis to 3millis).

This function can be further improved to display "."(dot) symbol next to the previous symbol instead of new symbol:

void TM1638lite::displayText(String text) {
  uint8_t length = text.length();
  for (uint8_t position = 0; position < 8 && position < length; position++){
	if(position+1 < length)
	  if(text[position+1] == '.'){
		displayASCIIwDot(position, text[position]);
		text.remove(position,1);
	  }
	  else
		displayASCII(position, text[position]);
	else
	  displayASCII(position, text[position]);
  }
}

void TM1638lite::displayASCIIwDot(uint8_t position, uint8_t ascii) {
  displaySS(position, ss[ascii] + 128);
}

Execution time with "."(dot) handling is 3.14millis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions