https://github.com/jakesmd/fastpin
An Arduino library for safe and high-speed digital read/write operations.
https://github.com/jakesmd/fastpin
arduino arduino-library digitalread digitalwrite
Last synced: 27 days ago
JSON representation
An Arduino library for safe and high-speed digital read/write operations.
- Host: GitHub
- URL: https://github.com/jakesmd/fastpin
- Owner: JakesMD
- License: mit
- Created: 2024-11-15T10:25:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-24T16:51:09.000Z (over 1 year ago)
- Last Synced: 2025-01-18T06:23:22.656Z (over 1 year ago)
- Topics: arduino, arduino-library, digitalread, digitalwrite
- Language: C++
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# FastPin
An Arduino library for safe and high-speed digital read/write operations.
## Stats
These stats were generated by running `Speed_Text.ino` on an Arduino clone.
The test measures how long it takes for the function to run 1,000 times and calculates the average duration. This process is repeated 1,000 times, and the final result is the average of all these averages. This approach compensates for the ±4 microsecond accuracy limitation of `micros()`.
### Read
- 1.32 microseconds
- 4.28 times faster than `digitalRead (5.66 microseconds)`
### Write
- 2.08 microseconds
- 2.36 times faster than `digitalWrite (4.91 microseconds)`
## Usage
``` cpp
#include
FastWritePin ledPin(LED_BUILTIN);
FastReadPin buttonPin(2);
void setup() {
ledPin.begin();
buttonPin.begin(true);
}
void loop() {
ledPin.write(buttonPin.read());
delay(50);
}
```
> ⚠️ FastPin only disables PWM timers in `begin()`. DO NOT use `analogWrite()` on the same pin.
## Optimizing Analog Reads for Speed
Analog reads are typically platform-specific operations. Nick Gammon has an excellent article detailing techniques to accelerate analog readings. You can explore it [here](https://www.gammon.com.au/adc).
## Contributions Welcome
We're open to contributions, especially for improvements in speed and efficiency. Feel free to open issues or pull requests with optimizations, feature requests, or bug reports to help make this project even better. Your input is valuable and appreciated!