diff --git a/README.md b/README.md index 2c61a62..31452ab 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,28 @@ ___ void displayText(String text, unsigned long scrollingSpeed); ``` +___ + +### Display a character on a 8x8 LED display. +* @param `index` - The index of the character to be displayed. The value is between 0 (0x00) and 255 (0xFF). You can find the characters corresponding to each index in the section below: +* @param `scrollingSpeed` - optional - The scrolling speed is between 1.0 (lowest speed) and 100.0 (highest speed). 90.0 is the default value. +```c++ + void displayCharacter(int index, unsigned long scrollingSpeed); +``` + +#### 8x8 Characters Overview +![](docs/images/font-8x8-overview.png) + +[image source][5] + +To know the index of a character we combine the column index with the row index. Both column and row index are hexadecimal values. + +For example the heart ❤ (column index: **0x** and row index: **x3**) is at index **0x03**. +```c++ + int heartIndex = 0x03; + render.displayCharacter(heartIndex); // display a scrolling heart ❤. +``` + --- ### ScrollingDirection enumeration @@ -110,3 +132,4 @@ enum CharacterOrientation [2]: https://osoyoo.com/2017/07/15/arduino-lesson-8x8-led-matrix [3]: https://mega.nz/folder/TI1QgAKQ#DpCOElh-b6mnEuqUMAVcqQ/folder/aAlUDCwZ [4]: http://arduino.cc/en/Guide/Libraries +[5]: http://www.gammon.com.au/forum/?id=11516 diff --git a/ScrollingText8x8Display.cpp b/ScrollingText8x8Display.cpp index 5d08ba0..3af42fe 100644 --- a/ScrollingText8x8Display.cpp +++ b/ScrollingText8x8Display.cpp @@ -62,6 +62,23 @@ void ScrollingText8x8Display::setCharacterInBuffer(byte newCharacter[DISPLAY_SIZ * @param scrollingSpeed - The scrolling speed is between 1.0 (lowest speed) and 100.0 (highest speed). 90.0 is the default value. */ void ScrollingText8x8Display::displayText(String text, unsigned long scrollingSpeed) +{ + int textLength = text.length(); + for (int i = 0; i < textLength; i++) + { + int charAsInt = (int)(text.charAt(i)); + + displayCharacter(charAsInt, scrollingSpeed); + } +} + +/** + * Display a character on a 8x8 LED display. + * + * @param index - The index of the character to be displayed. The value is between 0 (0x00) and 255 (0xFF). You can find the characters corresponding to each index here: https://github.com/TheJLifeX/ScrollingText8x8Display#8x8-characters-overview + * @param scrollingSpeed - The scrolling speed is between 1.0 (lowest speed) and 100.0 (highest speed). 90.0 is the default value. + */ +void ScrollingText8x8Display::displayCharacter(int index, unsigned long scrollingSpeed) { float duration = map( scrollingSpeed, @@ -70,24 +87,18 @@ void ScrollingText8x8Display::displayText(String text, unsigned long scrollingSp MAXIMAL_DURATION_FOR_ONE_CHARACTER, minimalDurationForOneCharacter); - int textLength = text.length(); - for (int i = 0; i < textLength; i++) + if (index < 0 || index >= NUMBER_OF_CHARACTERS) { - int charAsInt = (int)(text.charAt(i)); - - if (charAsInt < 0 || charAsInt >= NUMBER_OF_CHARACTERS) - { - charAsInt = UNKNOW_CHARACTER; - } + index = UNKNOW_CHARACTER; + } - byte asciiCharacter[DISPLAY_SIZE]; - for (int k = 0; k < DISPLAY_SIZE; k++) - { - // `pgm_read_byte` function documentation, see: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/ - asciiCharacter[k] = pgm_read_byte(&(font_8x8[charAsInt][k])); - } - displayScrolling_8x8_AsciiCharacter(asciiCharacter, duration); + byte asciiCharacter[DISPLAY_SIZE]; + for (int k = 0; k < DISPLAY_SIZE; k++) + { + // `pgm_read_byte` function documentation, see: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/ + asciiCharacter[k] = pgm_read_byte(&(font_8x8[index][k])); } + displayScrolling_8x8_AsciiCharacter(asciiCharacter, duration); } /** diff --git a/ScrollingText8x8Display.h b/ScrollingText8x8Display.h index c954ac8..5de9847 100644 --- a/ScrollingText8x8Display.h +++ b/ScrollingText8x8Display.h @@ -48,6 +48,7 @@ class ScrollingText8x8Display ScrollingDirection scrollingDirection = RIGHT_TO_LEFT, CharacterOrientation characterOrientation = TOP); void displayText(String text, unsigned long scrollingSpeed = DEFAULT_SCROLLING_SPEED); + void displayCharacter(int index, unsigned long scrollingSpeed = DEFAULT_SCROLLING_SPEED); private: // Time to wait after one frame is displayed. In a frame a single row of LEDs (8 LEDs) are diplayed. diff --git a/docs/images/font-8x8-overview.png b/docs/images/font-8x8-overview.png new file mode 100644 index 0000000..8b241f2 Binary files /dev/null and b/docs/images/font-8x8-overview.png differ diff --git a/keywords.txt b/keywords.txt index 645d8b0..901dce6 100644 --- a/keywords.txt +++ b/keywords.txt @@ -3,6 +3,7 @@ ScrollingText8x8Display KEYWORD1 init KEYWORD2 displayText KEYWORD2 +displayCharacter KEYWORD2 ScrollingDirection KEYWORD3 TOP_TO_BOTTOM LITERAL1