Characteristic Locus
Inherited Members IPort<IAnalogChannelInfo>.Channel IPort<IAnalogChannelInfo>.Pin System.IDisposable.Dispose() System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>.Subscribe(System.IObserver<Meadow.IChangeResult<Meadow.Units.Voltage>>)
Namespace Meadow.Hardware
Assembly Meadow.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

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

The average buffer value.

VoltageSampleBuffer

Gets the sample buffer.

Declaration
IList<Voltage> VoltageSampleBuffer { get; }

Property Value

Type Description
System.Collections.Generic.IList<Voltage>

The sample buffer.

Methods

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

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

Parameters

Type Name Description
System.Action<IChangeResult<Voltage>> handler
System.Predicate<IChangeResult<Voltage>> filter

Returns

Type Description
FilterableChangeObserver<Voltage>

Read(Int32, Int32)

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

Declaration
Task<Voltage> Read(int sampleCount = 10, int sampleIntervalDuration = 40)

Parameters

Type Name Description
System.Int32 sampleCount

The number of sample readings to take. Must be greater than 0. These samples are automatically averaged.

System.Int32 sampleIntervalDuration

The time, in milliseconds, to wait in between samples during a reading.

Returns

Type Description
System.Threading.Tasks.Task<Voltage>

A float value that's ann average value of all the samples taken.

StartUpdating(Int32, Int32, Int32)

Starts continuously sampling the analog port.

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

Declaration
void StartUpdating(int sampleCount = 10, int sampleIntervalDuration = 40, int standbyDuration = 100)

Parameters

Type Name Description
System.Int32 sampleCount

How many samples to take during a given reading. These are automatically averaged to reduce noise.

System.Int32 sampleIntervalDuration

The time, in milliseconds, to wait in between samples during a reading.

System.Int32 standbyDuration

The time, in milliseconds, to wait between sets of sample readings. This value determines how often Changed events are raised and IObservable consumers are notified.

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
System.EventHandler<IChangeResult<Voltage>>