Characteristic Locus
Inheritance System.Object PortBase<Meadow.Hardware.IAnalogChannelInfo> AnalogPortBase AnalogInputPortBase > AnalogInputPort
Implements Meadow.Hardware.IAnalogInputPort Meadow.Hardware.IAnalogPort Meadow.Hardware.IPort<Meadow.Hardware.IAnalogChannelInfo> IDisposable IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>> IObservable<Meadow.IChangeResult<Voltage>>
Inherited Members AnalogInputPortBase.Updated AnalogInputPortBase.VoltageSampleBuffer AnalogInputPortBase.UpdateInterval AnalogInputPortBase.SampleCount AnalogInputPortBase.SampleInterval AnalogInputPortBase.ReferenceVoltage AnalogInputPortBase.Voltage AnalogInputPortBase.observers AnalogInputPortBase.RaiseChangedAndNotify(IChangeResult<Voltage>) AnalogInputPortBase.Subscribe(IObserver<IChangeResult<Voltage>>) PortBase<IAnalogChannelInfo>.disposed PortBase<IAnalogChannelInfo>.Channel PortBase<IAnalogChannelInfo>.Pin
Namespace Meadow.Hardware
Assembly Meadow.dll

Syntax

public class AnalogInputPort : AnalogInputPortBase, IAnalogInputPort, IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>, IObservable<IChangeResult<Voltage>>

Constructors

AnalogInputPort(IPin, IMeadowIOController, IAnalogChannelInfo, Int32, Int32, Single)

Declaration
protected AnalogInputPort(IPin pin, IMeadowIOController ioController, IAnalogChannelInfo channel, int sampleCount, int sampleIntervalMs, float referenceVoltage)

Parameters

Type Name Description
Meadow.Hardware.IPin pin
Meadow.Hardware.IMeadowIOController ioController
Meadow.Hardware.IAnalogChannelInfo channel
System.Int32 sampleCount
System.Int32 sampleIntervalMs
System.Single referenceVoltage

Fields

_previousVoltageReading

Declaration
protected Voltage? _previousVoltageReading

Field Value

Type Description
System.Nullable<Voltage>

Properties

IOController

Declaration
protected IMeadowIOController IOController { get; }

Property Value

Type Description
Meadow.Hardware.IMeadowIOController

IsSampling

Gets a value indicating whether the analog input port is currently sampling the ADC. Call StartSampling() to spin up the sampling process.

Declaration
public bool IsSampling { get; protected set; }

Property Value

Type Description
System.Boolean

true if sampling; otherwise, false.

Methods

Dispose()

Declaration
public override void Dispose()

Overrides

Meadow.Hardware.PortBase<Meadow.Hardware.IAnalogChannelInfo>.Dispose()

From(IPin, IMeadowIOController, Int32, Int32, Single)

Declaration
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount = 5, int sampleIntervalMs = 40, float referenceVoltage = 3.3F)

Parameters

Type Name Description
Meadow.Hardware.IPin pin
Meadow.Hardware.IMeadowIOController ioController
System.Int32 sampleCount
System.Int32 sampleIntervalMs
System.Single referenceVoltage

Returns

Type Description
AnalogInputPort

Read()

Convenience method to get the voltage value. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
public override Task<Voltage> Read()

Returns

Type Description
Task<Voltage>

The raw value between 0 and x. TODO: @Ctacke 0 and what? Int.Max?

Overrides

StartUpdating(Nullable<TimeSpan>)

Starts sampling the ADC and populating the sample buffer with values.

When sampling, the AnalogInputPort will take multiple readings (samples); waiting for the sampleIntervalDuration in between them, and fill the sample buffer with those values, then sleep for the duration specified in readIntervalDuration.

This method also starts the raising of events and IObservable subscribers to get notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public override void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

A TimeSpan to wait between sets of sample readings. This value determines how often Changed events are raised and IObservable consumers are notified.

Overrides

StopUpdating()

Spins down the process sampling the ADC. Any values in the SampleBuffer will become stale after calling this method.

Declaration
public override void StopUpdating()

Overrides