Characteristic Locus
Inherited Members IPort<IAnalogChannelInfo>.Channel IPort<IAnalogChannelInfo>.Pin IDisposable.Dispose() IObservable<IChangeResult<Voltage>>.Subscribe(IObserver<IChangeResult<Voltage>>)
Namespace Meadow.Hardware
Assembly Meadow.Contracts.dll

Syntax

public interface IAnalogInputPort : IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>

Properties

ReferenceVoltage

The maximum voltage that the Analog Port can read. Typically 3.3V. This value is used to convert raw ADC values into voltage.

Declaration
Voltage ReferenceVoltage { get; }

Property Value

Type Description
Voltage

SampleCount

Number of samples to take per reading. If > 0, then the port will take multiple readings and automatically average them to reduce noise, a process known as oversampling.

Declaration
int SampleCount { get; }

Property Value

Type Description
int

SampleInterval

Duration between samples when oversampling.

Declaration
TimeSpan SampleInterval { get; }

Property Value

Type Description
TimeSpan

UpdateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often Updated events are raised and IObservable consumers are notified.

Declaration
TimeSpan UpdateInterval { get; }

Property Value

Type Description
TimeSpan

Voltage

Gets the average value of the values in the buffer. Use in conjunction with StartSampling() for long-running analog sampling. For occasional sampling, use Read().

Declaration
Voltage Voltage { get; }

Property Value

Type Description
Voltage

VoltageSampleBuffer

Gets the sample buffer.

Declaration
Voltage[] VoltageSampleBuffer { get; }

Property Value

Type Description
Voltage[]

Methods

CreateObserver(Action<IChangeResult<Voltage>>, Predicate<IChangeResult<Voltage>>?)

Creates an observer for monitoring changes in the analog input voltage.

Declaration
public static FilterableChangeObserver<Voltage> CreateObserver(Action<IChangeResult<Voltage>> handler, Predicate<IChangeResult<Voltage>>? filter = null)

Parameters

Type Name Description
Action<IChangeResult<Voltage>> handler

The handler to be called when a change occurs.

Predicate<IChangeResult<Voltage>> filter

An optional filter predicate for filtering changes.

Returns

Type Description
FilterableChangeObserver<Voltage>

The created observer.

Read()

Gets the current voltage. For frequent reads, use StartUpdating() and StopUpdating() in conjunction with the SampleBuffer.

Declaration
Task<Voltage> Read()

Returns

Type Description
Task<Voltage>

The current voltage.

StartUpdating(TimeSpan?)

Starts continuously sampling the analog port.

This method also starts raising Updated events and notifying IObservable subscribers. Use the updateInterval parameter to specify how often events and notifications are raised.

Declaration
void StartUpdating(TimeSpan? updateInterval = null)

Parameters

Type Name Description
TimeSpan? updateInterval

The interval between readings.

StopUpdating()

Stops sampling the analog port.

Declaration
void StopUpdating()

Events

Updated

Raised when the value of the reading changes.

Declaration
event EventHandler<IChangeResult<Voltage>> Updated

Event Type

Type Description
EventHandler<IChangeResult<Voltage>>