Skip to content

Commit

Permalink
Implement display character.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJLifeX committed Jun 22, 2020
1 parent eb44a33 commit 951e493
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
41 changes: 26 additions & 15 deletions ScrollingText8x8Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions ScrollingText8x8Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added docs/images/font-8x8-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ScrollingText8x8Display KEYWORD1
init KEYWORD2
displayText KEYWORD2
displayCharacter KEYWORD2

ScrollingDirection KEYWORD3
TOP_TO_BOTTOM LITERAL1
Expand Down

0 comments on commit 951e493

Please sign in to comment.