Interface IAnalogInputPort
Contract for ports that implement an analog input channel.
Assembly: Meadow.Contracts.dll
View Source
public interface IAnalogInputPort : IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>
Properties
VoltageSampleBuffer
Gets the sample buffer.
View Source
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
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
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
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
int SampleCount { get; }
SampleInterval
Duration between samples when oversampling.
View Source
TimeSpan SampleInterval { get; }
Methods
Read()
Gets the current voltage. For frequent reads, use StartUpdating() and StopUpdating() in conjunction with the SampleBuffer.
View Source
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
void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.TimeSpan> | updateInterval | The interval between readings. |
StopUpdating()
Stops sampling the analog port.
View Source
void StopUpdating()
CreateObserver(Action<IChangeResult<Voltage>>, Predicate<IChangeResult<Voltage>>?)
Creates an observer for monitoring changes in the analog input voltage.
View Source
public static FilterableChangeObserver<Voltage> CreateObserver(Action<IChangeResult<Voltage>> handler, Predicate<IChangeResult<Voltage>>? filter = null)
Returns
Meadow.FilterableChangeObserver<UNIT>: The created observer.
Parameters
Type | Name | Description |
---|---|---|
System.Action<Meadow.IChangeResult<Meadow.Units.Voltage>> | handler | The handler to be called when a change occurs. |
System.Predicate<Meadow.IChangeResult<Meadow.Units.Voltage>> | filter | An optional filter predicate for filtering changes. |
Events
Updated
Raised when the value of the reading changes.
View Source
event EventHandler<IChangeResult<Voltage>> Updated
Event Type
System.EventHandler<Meadow.IChangeResult<Meadow.Units.Voltage>>