Skip to main content

Class AnalogInputPort

Represents a port that is capable of reading analog input.

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

Inheritance: System.Object -> Meadow.Hardware.PortBase<C>

Implements:
Meadow.Hardware.IAnalogInputPort, System.IDisposable, System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>

Properties​

IOController​

Gets the IOController device

View Source​
Declaration
protected IMeadowIOController IOController { get; }

IsSampling​

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

View Source​
Declaration
public bool IsSampling { get; protected set; }

PreviousVoltageReading​

Gets or sets the previous voltage reading

View Source​
Declaration
protected Voltage? PreviousVoltageReading { get; set; }

Fields​

DefaultSampleInterval​

The default sampling interval for the Input (40ms)

View Source​
Declaration
public static readonly TimeSpan DefaultSampleInterval

DefaultReferenceVoltage​

The default reference voltage for the Input (3.3V)

View Source​
Declaration
public static readonly Voltage DefaultReferenceVoltage

Methods​

From(IPin, IMeadowIOController, int)​

Creates an AnalogInputPort given the provided parameters

View Source​
Declaration
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount = 5)
Returns​

Meadow.Hardware.AnalogInputPort

Parameters​
TypeName
Meadow.Hardware.IPinpin
Meadow.Hardware.IMeadowIOControllerioController
System.Int32sampleCount

From(IPin, IMeadowIOController, int, TimeSpan, Voltage)​

Creates an AnalogInputPort given the provided parameters

View Source​
Declaration
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount, TimeSpan sampleInterval, Voltage referenceVoltage)
Returns​

Meadow.Hardware.AnalogInputPort

Parameters​
TypeName
Meadow.Hardware.IPinpin
Meadow.Hardware.IMeadowIOControllerioController
System.Int32sampleCount
System.TimeSpansampleInterval
Meadow.Units.VoltagereferenceVoltage
Exceptions​

System.ArgumentException

System.Exception

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

View Source​
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters​
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalA TimeSpan to wait
 between sets of sample readings. This value determines how often
`Changed` events are raised and `IObservable` consumers are notified. |

StopUpdating()​

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

View Source​
Declaration
public override void StopUpdating()

Read()​

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

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

System.Threading.Tasks.Task<Meadow.Units.Voltage>: Read Voltage

Implements​