ASCII include file (ASCII.h)

Is there an ASCII include file (ASCII.h or something similar) in the set of Arduino files?

Thanks,

Jack

You have to say what you are doing, where you think this might be necessary, but here is an example of using an ascii value to address a font table for a display:

uint32_t getFontbyAscii(char inChar) {
  // use ascii code value to address the font table.
  // assumes font table layout 10 digits followed by 26 letters.
  // change this if you add/delete entries in the font[] table.
  if (inChar >= '0' && inChar <= '9') return font[inChar - '0'];
  if (inChar >= 'A' && inChar <= 'Z') return font[10 + inChar - 'A'];
  if (inChar >= 'a' && inChar <= 'z') return font[10 + inChar - 'a'];
  // we're still here so unsupported ascii code
  return 0;  // blank
}

What do you need such a file for ?

You do not mean ANSI.h

(escape sequences to control an ANSI terminal e.g. VT100)

Besides all the other questions, what would an ASCII include file look like? Examples?

I know this file exists SSD1306Ascii.h, probably there are more displays with ascii files.

There are three libs with ASCII in its name, floatToASCII, AsciiMassage, zaber-ascii-for-arduino ?

Finally my RS485 lib has defines for ASCII control characters.

#pragma once
//
//    FILE: ASCII_CONTROL.h
//  AUTHOR: Rob Tillaart
//    DATE: 2020-08-26
// PURPOSE: ASCII control characters
//     URL: https://github.com/RobTillaart/RS485


#define ASCII_NUL     0x00    //  NULL char
#define ASCII_SOH     0x01    //  Start Of Header
#define ASCII_STX     0x02    //  Start of Text
#define ASCII_ETX     0x03    //  End of Text
#define ASCII_EOT     0x04    //  End of Transmission
#define ASCII_ENQ     0x05    //  ENQuiry
#define ASCII_ACK     0x06    //  ACKnowledge
#define ASCII_BEL     0x07    //  Bell
#define ASCII_BS      0x08    //  Back Space
#define ASCII_TAB     0x09    //  TAB char
#define ASCII_LF      0x0A    //  Line Feed
#define ASCII_VT      0x0B    //  Vertical TAB
#define ASCII_FF      0x0C    //  Form Feed
#define ASCII_CR      0x0D    //  Carriage Return
#define ASCII_SO      0x0E    //  Shift Out
#define ASCII_SI      0x0F    //  Shift In
#define ASCII_DLE     0x10    //  Data Link Escape
#define ASCII_DC1     0x11    //  Device Control 1
#define ASCII_DC2     0x12    //  Device Control 2
#define ASCII_DC3     0x13    //  Device Control 3
#define ASCII_DC4     0x14    //  Device Control 4
#define ASCII_NAK     0x15    //  NOT ACKnowledge
#define ASCII_SYN     0x16    //  Synchronous idle
#define ASCII_ETB     0x17    //  End of transmission block
#define ASCII_CAN     0x18    //  CANcel
#define ASCII_EM      0x19    //  End of Medium
#define ASCII_SUB     0x1A    //  Substitute
#define ASCII_ESC     0x1B    //  Escape
#define ASCII_FS      0x1C    //  File Separator
#define ASCII_GS      0x1D    //  Group Separator
#define ASCII_RS      0x1E    //  Record Separator
#define ASCII_US      0x1F    //  Unit Separator
#define ASCII_DEL     0x7F    //  DELete


//  -- END OF FILE --

C pretty much assumes everything is ASCII.
ctype.h includes functions you might be looking for:

int     isalnum (int __c)                                                                       
int     isalpha (int __c)                                                                       
int     isascii (int __c)                                                                       
int     isblank (int __c)                                                                       
int     iscntrl (int __c)                                                                       
int     isdigit (int __c)                                                                       
int     isgraph (int __c)                                                                       
int     islower (int __c)                                                                       
int     isprint (int __c)                                                                       
int     ispunct (int __c)                                                                       
int     isspace (int __c)                                                                       
int     isupper (int __c)                                                                       
int     isxdigit (int __c)                                                                      
                                                                                                
int     toascii (int __c)                                                                       
int     tolower (int __c)                                                                       
int     toupper (int __c)                                                                       

Sorry I didn’t reply to this sooner.

robtillaart answered the question as to what one might look like in the file ASCII_CONTROL.h that he posted – Thanks.

As to why, suppose in my code I was looking for an Escape character for some reason. It’s much easier to write if(ch == ASCII_ESC) than have to think for a second, okay what’s the ASCII hex code for an ESC character, look it up in a table, find that it’s 0x1b and then write if(cr == 0x1b).

It’s also more supportable for the next guy that has to look at the code (what the heck is a 0x1b???) to fix a bug (not that my code EVER has bugs), or make a modification.

Thanks,

Jack

Thank you for the answer in your reply. But, if people would add a comment on that line of code, all would be so much easier.

Yes, I agree. I remember many years ago when I first started coding in C++, it was touted as a “self-commenting” language. That might be true if you were the only person to ever touch the code and if you had a good memory for why you did something years ago, but reasonable comments are essential to good maintainable code.