Skip to content

Instantly share code, notes, and snippets.

@a13ssandr0
Last active October 17, 2022 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a13ssandr0/76b78f302e55b6b9d5d88ed2909e07db to your computer and use it in GitHub Desktop.
Save a13ssandr0/76b78f302e55b6b9d5d88ed2909e07db to your computer and use it in GitHub Desktop.
C++ lookup table for converting ASCII characters in 7 segment representations
/**
* C++ ASCII to 7 seg digits converter
*
* This array aims at being as complete as possible,
* if you find any character that could be added or
* modified, just leave a comment specifying
* the decimal ascii code of the character and
* the hexadecimal code of the segment combination
* hex(0b0abcdefg)
* __________
* |\ __a___ /|
* | | | |
* |f| |b|
* | |______| |
* |< __g___ >|
* | | | |
* |e| |c|
* | |______| |
* |/___d____\|
*
* Examples:
* Char ASCII Hex
* A 65 0x77
* 8 56 0x7F
* 0 48 0x7E
*
*
* Usage:
* char c = 'A';
* uint8_t digit = ascii7seg[c];
*
*/
static const uint8_t ascii7seg[]= {
0, // Null char
0, // Start of Heading
0, // Start of Text
0, // End of Text
0, // End of Transmission
0, // Enquiry
0, // Acknowledgment
0, // Bell
0, // Back Space
0, // Horizontal Tab
0, // Line Feed
0, // Vertical Tab
0, // Form Feed
0, // Carriage Return
0, // Shift Out / X-On
0, // Shift In / X-Off
0, // Data Line Escape
0, // Device Control 1 (oft. XON)
0, // Device Control 2
0, // Device Control 3 (oft. XOFF)
0, // Device Control 4
0, // Negative Acknowledgement
0, // Synchronous Idle
0, // End of Transmit Block
0, // Cancel
0, // End of Medium
0, // Substitute
0, // Escape
0, // File Separator
0, // Group Separator
0, // Record Separator
0, // Unit Separator
0, // Space
0, // !
0x22, // "
0, // #
0, // $
0, // %
0, // &
0x02, // '
0x4E, // (
0x78, // )
0, // *
0, // +
0x04, // ,
0x01, // -
0, // .
0, // /
0x7E, // 0
0x30, // 1
0x6D, // 2
0x79, // 3
0x33, // 4
0x5B, // 5
0x5F, // 6
0x70, // 7
0x7F, // 8
0x7B, // 9
0, // :
0, // ;
0, // <
0x09, // =
0, // >
0x65, // ?
0, // @
0x77, // A
0x1F, // B
0x4E, // C
0x3D, // D
0x4F, // E
0x47, // F
0x5E, // G
0x37, // H
0x30, // I
0x3C, // J
0x57, // K
0x0E, // L
0x55, // M
0x15, // N
0x1D, // O
0x67, // P
0x73, // Q
0x05, // R
0x5B, // S
0x0F, // T
0x3E, // U
0x1C, // V
0x5C, // W
0x13, // X
0x3B, // Y
0x6D, // Z
0x4E, // [
0, // \ //This comment avoids misinterpretation of the backslash at the end of the line
0x78, // ]
0, // ^
0x08, // _
0x02, // `
0x77, // a
0x1F, // b
0x4E, // c
0x3D, // d
0x4F, // e
0x47, // f
0x5E, // g
0x37, // h
0x06, // i
0x3C, // j
0x57, // k
0x0E, // l
0x55, // m
0x15, // n
0x1D, // o
0x67, // p
0x73, // q
0x05, // r
0x5B, // s
0x0F, // t
0x3E, // u
0x1C, // v
0x5C, // w
0x13, // x
0x3B, // y
0x6D, // z
0, // {
0, // |
0, // }
0, // ~
0, // Delete
0, // €
0, // EMPTY
0x04, // ‚
0, // ƒ
0x14, // „
0, // …
0, // †
0, // ‡
0, // ˆ
0, // ‰
0, // Š
0, // ‹
0, // Œ
0, // EMPTY
0, // Ž
0, // EMPTY
0, // EMPTY
0x20, // ‘
0x02, // ’
0x22, // “
0x22, // ”
0, // •
0x01, // –
0x01, // —
0, // ˜
0, // ™
0, // š
0, // ›
0, // œ
0, // EMPTY
0, // ž
0, // Ÿ
0, // Non-breaking space
0, // ¡
0, // ¢
0, // £
0, // ¤
0, // ¥
0x06, // ¦
0, // §
0, // ¨
0, // ©
0, // ª
0, // «
0x11, // ¬
0, // ­ Soft hyphen
0, // ®
0x40, // ¯
0x63, // °
0, // ±
0, // ²
0, // ³
0x02, // ´
0, // µ
0, // ¶
0, // ·
0, // ¸
0, // ¹
0x63, // º
0, // »
0, // ¼
0, // ½
0, // ¾
0x2D, // ¿
0, // À
0, // Á
0, // Â
0, // Ã
0, // Ä
0, // Å
0, // Æ
0, // Ç
0, // È
0, // É
0, // Ê
0, // Ë
0, // Ì
0, // Í
0, // Î
0, // Ï
0, // Ð
0, // Ñ
0, // Ò
0, // Ó
0, // Ô
0, // Õ
0, // Ö
0, // ×
0, // Ø
0, // Ù
0, // Ú
0, // Û
0, // Ü
0, // Ý
0, // Þ
0, // ß
0, // à
0, // á
0, // â
0, // ã
0, // ä
0, // å
0, // æ
0, // ç
0, // è
0, // é
0, // ê
0, // ë
0, // ì
0, // í
0, // î
0, // ï
0, // ð
0, // ñ
0, // ò
0, // ó
0, // ô
0, // õ
0, // ö
0, // ÷
0, // ø
0, // ù
0, // ú
0, // û
0, // ü
0, // ý
0, // þ
0 // ÿ
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment