6.0 Leveraging Arduino Libraries
The Arduino environment includes a rich set of standard libraries that abstract away low-level details and simplify complex tasks, from mathematical calculations to character manipulation. These pre-built code collections significantly accelerate development by providing tested, reusable functions. This section serves as a reference for some of the most commonly used standard libraries for handling time, characters, and mathematics.
6.1 Time Functions
These functions are essential for controlling the timing and sequencing of operations in a sketch.
| Function | Description |
| delay(ms) | Pauses the program for the specified amount of time in milliseconds. |
| delayMicroseconds(us) | Pauses the program for the specified amount of time in microseconds. |
| millis() | Returns the number of milliseconds since the Arduino board began running the current program. This number overflows (resets to zero) after approximately 50 days. |
| micros() | Returns the number of microseconds since the Arduino board began running the current program. This number overflows after approximately 70 minutes. |
6.2 Character Functions ()
The character-handling library provides a suite of functions for testing and manipulating character data. These are particularly useful when parsing serial input or other text-based data. To use them, you must include the <cctype> header.
| Function Prototype | Description |
| int isdigit(int c) | Returns true (non-zero) if c is a digit (0-9). |
| int isalpha(int c) | Returns true if c is a letter (a-z, A-Z). |
| int isalnum(int c) | Returns true if c is a digit or a letter. |
| int isxdigit(int c) | Returns true if c is a hexadecimal digit character (0-9, a-f, A-F). |
| int islower(int c) | Returns true if c is a lowercase letter. |
| int isupper(int c) | Returns true if c is an uppercase letter. |
| int isspace(int c) | Returns true if c is a whitespace character (e.g., space, tab, newline). |
| int iscntrl(int c) | Returns true if c is a control character (e.g., newline, tab). |
| int ispunct(int c) | Returns true if c is a punctuation character (not a space, digit, or letter). |
| int isprint(int c) | Returns true if c is a printing character, including space. |
| int isgraph(int c) | Returns true if c is a printing character other than space. |
6.3 Math Library ()
The standard C math library, included via <math.h>, provides a collection of functions for performing mathematical operations on floating-point numbers.
| Function | Description |
| acos(double x) | Computes the arc cosine of x. |
| asin(double x) | Computes the arc sine of x. |
| atan(double x) | Computes the arc tangent of x. |
| cos(double x) | Returns the cosine of x. |
| sin(double x) | Returns the sine of x. |
| tan(double x) | Returns the tangent of x. |
| exp(double x) | Returns the exponential value of x (e^x). |
| fabs(double x) | Computes the absolute value of a floating-point number x. |
| fmod(double x, double y) | Returns the floating-point remainder of x / y. |
| log(double x) | Returns the natural logarithm of x. |
| pow(double x, double y) | Returns the value of x raised to the power of y. |
| sqrt(double x) | Returns the non-negative square root of x. |
| square(double x) | Returns x * x. (Note: this is an Arduino-specific addition). |
The trigonometric functions (sin, cos, tan, etc.) expect their input arguments to be in radians, not degrees.
While libraries offer pre-built solutions, building more sophisticated applications often requires mastering advanced programming techniques like handling external events with interrupts.