Class SimulatedAnalogInputPort
Represents a simulated analog input port
Assembly: Meadow.Foundation.dll
View Source
public class SimulatedAnalogInputPort : SimulatedSensorBase, ISimulatedSensor, IAnalogInputPort, IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>
Inheritance: System.Object
-> Meadow.Foundation.Sensors.SimulatedSensorBase
Implements:
Meadow.Peripherals.Sensors.ISimulatedSensor
, Meadow.Hardware.IAnalogInputPort
, Meadow.Hardware.IAnalogPort
, Meadow.Hardware.IPort<Meadow.Hardware.IAnalogChannelInfo>
, System.IDisposable
, System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>
Properties
VoltageSampleBuffer
Gets the sample buffer.
View Source
public 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
public Voltage ReferenceVoltage { get; set; }
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
public 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
public 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
public int SampleCount { get; }
SampleInterval
Duration between samples when oversampling.
View Source
public TimeSpan SampleInterval { get; }
Channel
Gets the channel associated with the port.
View Source
public IAnalogChannelInfo Channel { get; }
Pin
Gets the pin associated with the port.
View Source
public IPin Pin { get; }
ValueType
Gets the type of the sensor's value.
View Source
public override Type ValueType { get; }
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
View Source
public void Dispose()
Read()
Gets the current voltage. For frequent reads, use StartUpdating() and StopUpdating() in conjunction with the SampleBuffer.
View Source
public 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
public 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
public void StopUpdating()
Subscribe(IObserver<IChangeResult<Voltage>>)
Notifies the provider that an observer is to receive notifications.
View Source
public IDisposable Subscribe(IObserver<IChangeResult<Voltage>> observer)
Returns
System.IDisposable
: A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them.
Parameters
Type | Name | Description |
---|---|---|
System.IObserver<Meadow.IChangeResult<Meadow.Units.Voltage>> | observer | The object that is to receive notifications. |
SetSensorValue(object)
Sets the simulated value for the sensor.
View Source
public override void SetSensorValue(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The value to set for the sensor. |
Events
Updated
Raised when the value of the reading changes.
View Source
public event EventHandler<IChangeResult<Voltage>>? Updated
Event Type
System.EventHandler<Meadow.IChangeResult<Meadow.Units.Voltage>>
Implements
Meadow.Peripherals.Sensors.ISimulatedSensor
Meadow.Hardware.IAnalogInputPort
Meadow.Hardware.IAnalogPort
Meadow.Hardware.IPort<Meadow.Hardware.IAnalogChannelInfo>
System.IDisposable
System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>