Open
Description
There is currently no function to get the current pin mode. A possible implementation is:
int pinMode(uint8_t pin)
{
if (pin >= NUM_DIGITAL_PINS) return (-1);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg = portModeRegister(port);
if (*reg & bit) return (OUTPUT);
volatile uint8_t *out = portOutputRegister(port);
return ((*out & bit) ? INPUT_PULLUP : INPUT);
}
The return value is the pin mode or error code (-1) for illegal pin number.
Cheers!