Skip to main content

Interface IAnalogInputPort

Contract for ports that implement an analog input channel.

Assembly: Meadow.Contracts.dll​
View Source​
Declaration
public interface IAnalogInputPort : IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>

Properties​

VoltageSampleBuffer​

Gets the sample buffer.

View Source​
Declaration
Voltage[] VoltageSampleBuffer { get; }

ReferenceVoltage​

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

View Source​
Declaration
Voltage ReferenceVoltage { get; }

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().

View Source​
Declaration
Voltage Voltage { get; }

UpdateInterval​

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

View Source​
Declaration
TimeSpan UpdateInterval { get; }

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.

View Source​
Declaration
int SampleCount { get; }

SampleInterval​

Duration between samples when oversampling.

View Source​
Declaration
TimeSpan SampleInterval { get; }

Methods​

Read()​

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

View Source​
Declaration
Task<Voltage> Read()
Returns​

System.Threading.Tasks.Task<Meadow.Units.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.

View Source​
Declaration
void StartUpdating(TimeSpan? updateInterval = null)
Parameters​
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalThe interval between readings.

StopUpdating()​

Stops sampling the analog port.

View Source​
Declaration
void StopUpdating()

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

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

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

Meadow.FilterableChangeObserver<UNIT>: The created observer.

Parameters​
TypeNameDescription
System.Action<Meadow.IChangeResult<Meadow.Units.Voltage>>handlerThe handler to be called when a change occurs.
System.Predicate<Meadow.IChangeResult<Meadow.Units.Voltage>>filterAn optional filter predicate for filtering changes.

Events​

Updated​

Raised when the value of the reading changes.

View Source​
Declaration
event EventHandler<IChangeResult<Voltage>> Updated
Event Type​

System.EventHandler<Meadow.IChangeResult<Meadow.Units.Voltage>>