Skip to content

Raspberry.IO.GeneralPurpose.PinConfiguration

raspberry-sharp edited this page Oct 14, 2012 · 7 revisions

Represents the configuration of a pin.

Introduction

The configuration of a pin may be defined either by using OutputPinConfiguration, InputPinConfiguration or SwitchInputPinConfiguration class initializers and properties, or in a more declarative way, using provided extension methods on ProcessorPin and ConnectorPin. The second option should be preferred for code readability reasons.

Declarative Configuration

Depending on pin direction, the following operations may be chained one after the other.

Input

static InputPinConfiguration PinConfigurationExtensionMethods.Input(ProcessorPin processPin);
static InputPinConfiguration PinConfigurationExtensionMethods.Input(ConnectorPin connectorPin);

Creates an InputPinConfiguration from a pin number.

Parameters
Samples
var input1 = ProcessorPin.P01.Input();
var input2 = ConnectorPin.P1Pin11.Input();

Output

static OutputPinConfiguration PinConfigurationExtensionMethods.Output(ProcessorPin pin);
static OutputPinConfiguration PinConfigurationExtensionMethods.Output(ConnectorPin pin);

Creates an OutputPinConfiguration from a pin number.

Parameters
Samples
var output1 = ProcessorPin.P02.Output();
var output2 = ConnectorPin.P1Pin13.Output();

Switch

static SwitchInputPinConfiguration Switch(this InputPinConfiguration configuration);

Indicates an input pin must act as a switch: its state only changes when the pin is released and its status become true.

Parameters
  • configuration: the input pin configuration
Samples
var button = ConnectorPin.P1Pin11.Input().Switch();

Name

static T Name<T>(this T configuration, string name) where T : PinConfiguration;

Affects a unique name to the specified pin.

Parameters
  • configuration: the pin configuration
  • name: the unique name of the pin
Samples
var led1 = ConnectorPin.P1Pin13.Output().Name("yellow");

Revert

static T Revert<T>(this T configuration) where T : PinConfiguration;

Reverts the meaning of the pin status: if set, when hardware pin is down, logical pin is true; when hardware pin is up, logical pin is false.

Parameters
  • configuration: the pin configuration
Samples
var led1 = ConnectorPin.P1Pin13.Output().Revert();

Enable

static OutputPinConfiguration Enable(this OutputPinConfiguration configuration);
static OutputPinConfiguration Enable(this SwitchInputPinConfiguration configuration);

Indicates the specified pin must be enabled (set to true) when it is added to the connection. This operation cannot be done on InputPinConfiguration.

Parameters
  • configuration: the pin configuration
Samples
var led1 = ConnectorPin.P1Pin13.Output().Enable();

Disable

static OutputPinConfiguration Disable(this OutputPinConfiguration configuration);
static OutputPinConfiguration Disable(this SwitchInputPinConfiguration configuration);

Indicates the specified pin must be diisabled(set to false) when it is added to the connection. This operation cannot be done on InputPinConfiguration.

Parameters
  • configuration: the pin configuration
Samples
var led1 = ConnectorPin.P1Pin13.Output().Disable();