Class GpioPin
A class representing a GPIO port (pin).
Inherited Members
Namespace: Unosquare.PiGpio.ManagedModel
Syntax
public sealed class GpioPin
Properties
Alerts
Provides GPIO change alert services. This provides more sophisticated notification settings but it is based on sampling.
Declaration
public GpioPinAlertService Alerts { get; }
Property Value
Type | Description |
---|---|
GpioPinAlertService |
Clock
Gets a hardware-based clock service. A clock channel spans multiple pins and therefore, clock frequency is not necessarily a per-pin setting.
Declaration
public GpioPinClockService Clock { get; }
Property Value
Type | Description |
---|---|
GpioPinClockService |
Direction
Gets or sets the direction of the pin.
Declaration
public PinDirection Direction { get; set; }
Property Value
Type | Description |
---|---|
PinDirection | The direction. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Unable to set the pin mode to an alternative function. |
Interrupts
Provides GPIO Interrupt Service Routine services. This is hardware-based input-only notifications.
Declaration
public GpioPinInterruptService Interrupts { get; }
Property Value
Type | Description |
---|---|
GpioPinInterruptService |
IsUserGpio
Gets a value indicating whether this pin is a user gpio (0 to 31) and also available on the current board type.
Declaration
public bool IsUserGpio { get; }
Property Value
Type | Description |
---|---|
Boolean |
Mode
Gets the current pin mode.
Declaration
public PinMode Mode { get; }
Property Value
Type | Description |
---|---|
PinMode |
PadId
Gets the electrical pad this pin belongs to.
Declaration
public GpioPadId PadId { get; }
Property Value
Type | Description |
---|---|
GpioPadId |
PinGpio
Gets the pin number as a system GPIO Identifier.
Declaration
public SystemGpio PinGpio { get; }
Property Value
Type | Description |
---|---|
SystemGpio |
PinNumber
Gets the BCM pin identifier.
Declaration
public int PinNumber { get; }
Property Value
Type | Description |
---|---|
Int32 |
PullMode
Gets or sets the resistor pull mode in input mode. You typically will need to set this to pull-up mode for most sensors to perform reliable reads.
Declaration
public GpioPullMode PullMode { get; set; }
Property Value
Type | Description |
---|---|
GpioPullMode |
Pwm
Gets the hardware-based PWM services associated to the pin. Hardware PWM groups several pins by their PWM channel.
Declaration
public GpioPinPwmService Pwm { get; }
Property Value
Type | Description |
---|---|
GpioPinPwmService |
Servo
Gets the servo pin service. This is a standard 50Hz PWM servo that operates in pulse widths between 500 and 2500 microseconds. Use the PWM service instead if you wish further flexibility.
Declaration
public GpioPinServoService Servo { get; }
Property Value
Type | Description |
---|---|
GpioPinServoService |
SoftPwm
Provides a sfotware based PWM pulse generator. This and the servo functionality use the DMA and PWM or PCM peripherals to control and schedule the pulse lengths and dutycycles. Using hardware based PWM is preferred.
Declaration
public GpioPinSoftPwmService SoftPwm { get; }
Property Value
Type | Description |
---|---|
GpioPinSoftPwmService |
Value
Gets or sets the digital value of the pin. This call actively reads or writes the pin.
Declaration
public bool Value { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
Pulsate(Int32, Boolean)
Pulsates the pin for the specified micro seconds. The value is the start value of the pulse.
Declaration
public void Pulsate(int microSecs, bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | microSecs | The micro secs. |
Boolean | value | if set to |
Read()
The fastest way to read from the pin. No error checking is performed.
Declaration
public int Read()
Returns
Type | Description |
---|---|
Int32 | Returns a 0 or a 1 for success. A negative number for error. |
Write(Int32)
The fastest way to write to the pin. Anything non-zero is a high. No error checking is performed.
Declaration
public ResultCode Write(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The value. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 (OK) for success. |