Arduino Pin Library v4.2.2
An easy to use Arduino library for fast and simultaneous operations on Arduino I/O pins.
|
An easy to use Arduino library for fast and simultaneous operations on Arduino I/O pins. Supports Arduino AVR boards natively and custom boards by manually defining register addresses. Complete documentation can be found here. Source code can be found here.
Background information about how direct port manipulation works can be found here.
Pin.getAnalogValue()
and Pin.setDutyCycle(int value)
not supported)Simple benchmark programs were created to compare this library to both the built in Arduino functions and direct port manipulation. The three benchmark programs are included in the examples/Benchmarks
directory. Each program switches pin 13 between HIGH and LOW as quickly as possible. The program flash memory usage and the frequency of the generated square wave are used for comparison. Results:
Filename | Flash Memory Usage | Output Frequency | |
---|---|---|---|
Arduino | Arduino-Benchmark.ino | 1,354 bytes | 64.91 kHz |
Pin Library | Pin-Library-Benchmark.ino | 1,164 bytes | 532.3 kHz |
Direct Port Manipulation | Port-Manipulation-Benchmark.ino | 648 bytes | 2661 kHz |
Install from the Arduino Library Manager or download the latest release here.
Without support for simultaneous operations
Single Pin
Array of Pins
Set mode to input
Enable pullup resistor
Disable pullup resistor
Set mode to output
Set HIGH
Set LOW
Get mode (INPUT/OUTPUT)
Get state (HIGH/LOW)
Get value (HIGH/LOW)
Get analog value (0-1023)
Toggle mode (OUTPUT -> INPUT, INPUT -> OUTPUT)
Toggle state (HIGH -> LOW, LOW -> HIGH)
Set duty cycle to ~50% (not every Pin supports PWM)
Special function specifically for timing using series resistor-capacitor circuits. Used to get analog information on digital pins. Connect the pin between the variable resistor (force sensitive resistor, photoresistor, etc.) and the capacitor. The function will charge the capacitor through the resistor and count down the timer until it is charged (50% voltage is considered charged). Finally, the capacitor is discharged to allow the function to be called again.
The function returns the value remaining on the counter when the pin state went to HIGH or 0 if the counter reached 0. The higher the resistance, the longer the capacitor will take to charge. Longer charge times mean the counter will be decremented more resulting in a lower value returned. Therefore, higher resistance -> lower value returned, lower resistance -> higher value returned.
Decrement a counter starting at 255 until the pin goes HIGH or the counter reaches 0
All Pins in array must use the same DDR, PORT, and PIN registers. Look at the Arduino documentation for your board to determine what registers each pin uses. Because this library is built for speed, the Pin Group is not automatically checked to be valid for simultaneous operations. An invalid array will produce unexpected results without error, therefore it is highly recommended that the array be validated using the isValid()
function during setup.
Import Pin Library with support for simultaneous operations
Create array of Pins for simultaneous operations
Check to ensure each Pin in PinGroup use the same registers
Simultaneously set mode for each Pin in PinGroup to INPUT
Simultaneously set mode for each Pin in PinGroup to OUTPUT
Simultaneously set state for each Pin in PinGroup to HIGH
Simultaneously set state for each Pin in PinGroup to LOW
Simultaneously check if each Pin in PinGroup is HIGH
Simultaneously check if each Pin in PinGroup is LOW
Simultaneously set each Pin in PinGroup to its opposite mode
Simultaneously set each Pin in PinGroup to its opposite state