Class AnalogInputPort
Represents a port that is capable of reading analog input.
Assembly: Meadow.dll
View Source
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
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
public bool IsSampling { get; protected set; }
PreviousVoltageReading
Gets or sets the previous voltage reading
View Source
protected Voltage? PreviousVoltageReading { get; set; }
Fields
DefaultSampleInterval
The default sampling interval for the Input (40ms)
View Source
public static readonly TimeSpan DefaultSampleInterval
DefaultReferenceVoltage
The default reference voltage for the Input (3.3V)
View Source
public static readonly Voltage DefaultReferenceVoltage
Methods
From(IPin, IMeadowIOController, int)
Creates an AnalogInputPort given the provided parameters
View Source
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount = 5)
Returns
Meadow.Hardware.AnalogInputPort
Parameters
Type | Name |
---|---|
Meadow.Hardware.IPin | pin |
Meadow.Hardware.IMeadowIOController | ioController |
System.Int32 | sampleCount |
From(IPin, IMeadowIOController, int, TimeSpan, Voltage)
Creates an AnalogInputPort given the provided parameters
View Source
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount, TimeSpan sampleInterval, Voltage referenceVoltage)
Returns
Meadow.Hardware.AnalogInputPort
Parameters
Type | Name |
---|---|
Meadow.Hardware.IPin | pin |
Meadow.Hardware.IMeadowIOController | ioController |
System.Int32 | sampleCount |
System.TimeSpan | sampleInterval |
Meadow.Units.Voltage | referenceVoltage |
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
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.TimeSpan> | updateInterval | A 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
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
public override Task<Voltage> Read()
Returns
System.Threading.Tasks.Task<Meadow.Units.Voltage>
: Read Voltage
Implements
- Meadow.Hardware.IAnalogInputPort
- Meadow.Hardware.IAnalogPort
- Meadow.Hardware.IPort<C>
System.IDisposable
System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>