Skip to main content

GpioPin Class

Namespace: GHIElectronics.TinyCLR.Devices.Gpio · Assembly: GHIElectronics.TinyCLR.Devices.Gpio

A single GPIO pin opened from a GpioController. Configure the direction with SetDriveMode(GpioPinDriveMode), then drive it with Write(GpioPinValue) or sample it with Read. Subscribe to ValueChanged for edge-triggered notifications on inputs.

public class GpioPin : IDisposable

Properties

PinNumber

public int PinNumber { get; }

The controller-relative pin index this object represents.

Controller

public GpioController Controller { get; }

The GpioController that owns this pin.

DebounceTimeout

public TimeSpan DebounceTimeout { get; set; }

Debounce window applied before ValueChanged fires. Transitions shorter than this duration are suppressed.

ValueChangedEdge

public GpioPinEdge ValueChangedEdge { get; set; }

Selects which edges raise ValueChanged. Defaults to both rising and falling. Updates take effect immediately if a handler is attached.

Methods

Dispose()

public void Dispose()

Releases the pin so another caller can open it.

IsDriveModeSupported(GpioPinDriveMode mode)

public bool IsDriveModeSupported(GpioPinDriveMode mode)

Tests whether a given drive mode is supported on this pin.

ParameterTypeDescription
modeGpioPinDriveModeThe drive mode to test.

Returns bool — True if the pin can be configured with the given mode.

IsDriveModeSupported(int pin, GpioPinDriveMode mode)

public bool IsDriveModeSupported(int pin, GpioPinDriveMode mode)

Obsolete. The pin argument is ignored — the pin's own PinNumber is used. Call the no-pin overload instead.

ParameterTypeDescription
pinintIgnored.
modeGpioPinDriveModeThe drive mode to test.

Returns bool — True if the pin can be configured with the given mode.

GetDriveMode()

public GpioPinDriveMode GetDriveMode()

Returns the pin's currently configured drive mode.

Returns GpioPinDriveMode

SetDriveMode(GpioPinDriveMode value)

public void SetDriveMode(GpioPinDriveMode value)

Configures the pin's electrical drive mode.

ParameterTypeDescription
valueGpioPinDriveModeNew drive mode. Must be supported on this pin (see IsDriveModeSupported(GpioPinDriveMode)).

Read()

public GpioPinValue Read()

Samples the pin and returns the current logical level.

Returns GpioPinValue — The pin's present GpioPinValue.

Write(GpioPinValue value)

public void Write(GpioPinValue value)

Drives an output pin to the specified level. No effect on input modes.

ParameterTypeDescription
valueGpioPinValueThe logical level to drive.

Toggle()

public void Toggle()

Inverts the pin's current output level. Equivalent to reading the current state and writing its opposite.

Events

ValueChanged

public event GpioPinValueChangedEventHandler ValueChanged

Raised when the pin transitions on an edge selected by ValueChangedEdge. The handler runs on the driver's event thread — keep it short and avoid blocking.