wayoda / LedControl

An Arduino library for MAX7219 and MAX7221 Led display drivers
Other
464 stars 246 forks source link

Function to print char array #39

Open m-maazi opened 4 years ago

m-maazi commented 4 years ago

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 ...');