wpi-32u4-library
Public Member Functions | Data Fields
FastGPIO::PinLoan< pin > Class Template Reference

#include <FastGPIO.h>

Public Member Functions

 PinLoan ()
 
 ~PinLoan ()
 

Data Fields

uint8_t state
 The state of the pin as returned from FastGPIO::Pin::getState. More...
 

Detailed Description

template<uint8_t pin>
class FastGPIO::PinLoan< pin >

This class saves the state of the specified pin in its constructor when it is created, and restores the pin to that state in its destructor. This can be very useful if a pin is being used for multiple purposes. It allows you to write code that temporarily changes the state of the pin and is guaranteed to restore the state later.

For example, if you were controlling both a button and an LED using a single pin and you wanted to see if the button was pressed without affecting the LED, you could write:

bool buttonIsPressed()
{
_delay_us(10);
}
static void setInputPulledUp() __attribute__((always_inline))
Sets a pin to be a digital input with the internal pull-up resistor enabled.
Definition: FastGPIO.h:342
static bool isInputHigh() __attribute__((always_inline))
Reads the input value of the pin.
Definition: FastGPIO.h:352

This is equivalent to:

bool buttonIsPressed()
{
_delay_us(10);
return value;
}
uint8_t state
The state of the pin as returned from FastGPIO::Pin::getState.
Definition: FastGPIO.h:488
static void setState(uint8_t state)
Sets the full 2-bit state of the pin.
Definition: FastGPIO.h:428
static uint8_t getState()
Returns the full 2-bit state of the pin.
Definition: FastGPIO.h:396

Definition at line 484 of file FastGPIO.h.

Constructor & Destructor Documentation

◆ PinLoan()

template<uint8_t pin>
FastGPIO::PinLoan< pin >::PinLoan ( )
inline

◆ ~PinLoan()

template<uint8_t pin>
FastGPIO::PinLoan< pin >::~PinLoan ( )
inline

Field Documentation

◆ state

template<uint8_t pin>
uint8_t FastGPIO::PinLoan< pin >::state

The state of the pin as returned from FastGPIO::Pin::getState.

Definition at line 488 of file FastGPIO.h.

Referenced by FastGPIO::PinLoan< pin >::PinLoan(), and FastGPIO::PinLoan< pin >::~PinLoan().


The documentation for this class was generated from the following file: