Skip to main content

Class SimulatedAnalogInputPort

Represents a simulated analog input port

Assembly: Meadow.Foundation.dll​
View Source​
Declaration
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​
Declaration
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​
Declaration
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​
Declaration
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​
Declaration
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​
Declaration
public int SampleCount { get; }

SampleInterval​

Duration between samples when oversampling.

View Source​
Declaration
public TimeSpan SampleInterval { get; }

Channel​

Gets the channel associated with the port.

View Source​
Declaration
public IAnalogChannelInfo Channel { get; }

Pin​

Gets the pin associated with the port.

View Source​
Declaration
public IPin Pin { get; }

ValueType​

Gets the type of the sensor's value.

View Source​
Declaration
public override Type ValueType { get; }

Methods​

Dispose()​

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source​
Declaration
public void Dispose()

Read()​

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

View Source​
Declaration
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​
Declaration
public void StartUpdating(TimeSpan? updateInterval = null)
Parameters​
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalThe interval between readings.

StopUpdating()​

Stops sampling the analog port.

View Source​
Declaration
public void StopUpdating()

Subscribe(IObserver<IChangeResult<Voltage>>)​

Notifies the provider that an observer is to receive notifications.

View Source​
Declaration
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​
TypeNameDescription
System.IObserver<Meadow.IChangeResult<Meadow.Units.Voltage>>observerThe object that is to receive notifications.

SetSensorValue(object)​

Sets the simulated value for the sensor.

View Source​
Declaration
public override void SetSensorValue(object value)
Parameters​
TypeNameDescription
System.ObjectvalueThe value to set for the sensor.

Events​

Updated​

Raised when the value of the reading changes.

View Source​
Declaration
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>>