LedControl icon indicating copy to clipboard operation
LedControl copied to clipboard

Function to print char array

Open m-maazi opened this issue 4 years ago • 0 comments

I don't know how to add this function to your useful library. This is what I wrote to print a char[] array to 7segment module:

void SEVSEG_PRINT(uint8_t arg1_ID, char arg2_DATA[]) {

      uint8_t tmp_LOCATION = 0;
      bool tmp_HAS_POINT = false;

      SEVSEG_MODULE.clearDisplay(arg1_ID);
      for (uint8_t i = 0; i < strlen(arg2_DATA); i++) {
        char tmp_CHAR = arg2_DATA[strlen(arg2_DATA) - i - 1];
        char tmp_CHAR_NEXT = arg2_DATA[strlen(arg2_DATA) - i - 2];
        if (tmp_CHAR == '.') {
          if (tmp_CHAR_NEXT == '.') {
            SEVSEG_MODULE.setChar(arg1_ID, tmp_LOCATION, '.', tmp_HAS_POINT);
            tmp_LOCATION++;
            tmp_HAS_POINT = false;
          } else {
            tmp_HAS_POINT = true;
          }
        } else if (isalpha(tmp_CHAR) || tmp_CHAR == ' ') {
          SEVSEG_MODULE.setChar(arg1_ID, tmp_LOCATION, tmp_CHAR, tmp_HAS_POINT);
          tmp_LOCATION++;
          tmp_HAS_POINT = false;
        } else if (isdigit(tmp_CHAR)) {
          SEVSEG_MODULE.setDigit(arg1_ID, tmp_LOCATION, tmp_CHAR - '0', tmp_HAS_POINT);
          tmp_LOCATION++;
          tmp_HAS_POINT = false;
        }
      }
}

I hope it helps! Try calling SEVSEG_PRINT(0, 'Hello ...');

m-maazi avatar Jul 05 '20 17:07 m-maazi