ArminJo / digitalWriteFast

Arduino library for faster and smaller digitalWrite(), digitalRead() and pinMode() functions using direct port manipulation for constant pin numbers.
BSD 3-Clause "New" or "Revised" License
25 stars 3 forks source link
# digitalWriteFast Arduino library for faster `digitalWrite()` using direct port manipulation and macro for ease in pin assignments **for constant pin numbers**. It also provides faster `pinMode()` and `digitalRead()` functions as well as it adds a `digitalToggleFast()` function. [![Badge License: BSD-3-Clause](https://img.shields.io/static/v1?label=license&message=BSD-3-Clause&color=blue)](https://opensource.org/licenses/BSD-3-Clause)     [![Badge Version](https://img.shields.io/github/v/release/ArminJo/digitalWriteFast?include_prereleases&color=yellow&logo=DocuSign&logoColor=white)](https://github.com/ArminJo/digitalWriteFast/releases/latest)     [![Badge Commits since latest](https://img.shields.io/github/commits-since/ArminJo/digitalWriteFast/latest?color=yellow)](https://github.com/ArminJo/digitalWriteFast/commits/master)     [![Badge Build Status](https://github.com/ArminJo/digitalWriteFast/workflows/LibraryBuild/badge.svg)](https://github.com/ArminJo/digitalWriteFast/actions)     ![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_digitalWriteFast) Available as [Arduino library "digitalWriteFast"](https://www.arduinolibraries.info/libraries/digitalWriteFast). [![Button Install](https://img.shields.io/badge/Install-brightgreen?logoColor=white&logo=GitBook)](https://www.ardu-badge.com/digitalWriteFast)     [![Button Changelog](https://img.shields.io/badge/Changelog-blue?logoColor=white&logo=AzureArtifacts)](https://github.com/ArminJo/digitalWriteFast?tab=readme-ov-file#revision-history)

If you find this library useful, please give it a star.

🌎 Google Translate


This is a fork of the subtree https://github.com/watterott/Arduino-Libs/tree/master/digitalWriteFast.

If pin number is no compile time constant, or the platform is not supported, then the regular Arduino functions digitalWrite() etc. are called.

Usage

Include the library: #include <digitalWriteFast.h>

Macro definitions:

Parameters:


Correct usage detection

Defining THROW_ERROR_IF_NOT_FAST would cause the macro to return an error during compilation, if the parameter is a variable and thus regular digital* functions must be called. This notifies the programmer the specific line where code is still slow.


Speed

For a 16 MHz Uno digitalWrite() is speed up from 5.8 µs to 125 ns, able to generate a 4 MHz signal instead of 86 kHz. More info in: /NOTES/NOTES.md

This is the waveform generated with the Timing example. Timing example signal

Compatibility

If you use megaTinyCore, you cannot use "#include digitalWriteFast.h" because megaTinyCore has it own digitalWriteFast function set, except digitalToggleFast().

Revision History

Version 1.2.1

Version 1.2.0

Version 1.1.0

Reference

This documentation is based on https://github.com/NicksonYap/digitalWriteFast/