/// <summary> /// Creates a Capacitive soil moisture sensor object with the especified AnalogInputPort. /// </summary> /// <param name="analogPort"></param> public Capacitive( IAnalogInputPort analogPort, float minimumVoltageCalibration = 0f, float maximumVoltageCalibration = 3.3f) { AnalogInputPort = analogPort; MinimumVoltageCalibration = minimumVoltageCalibration; MaximumVoltageCalibration = maximumVoltageCalibration; // wire up our observable // have to convert from voltage to temp units for our consumers // this is where the magic is: this allows us to extend the IObservable // pattern through the sensor driver AnalogInputPort.Subscribe( new FilterableChangeObserver <FloatChangeResult, float>( h => { var newMoisture = VoltageToMoisture(h.New); var oldMoisture = VoltageToMoisture(h.Old); Moisture = newMoisture; // save state RaiseChangedAndNotify(new FloatChangeResult( newMoisture, oldMoisture)); }) ); }
public AnalogWaterLevel(IAnalogInputPort analogInputPort, Calibration calibration = null) { AnalogInputPort = analogInputPort; // // If the calibration object is null use the defaults for TMP35. // LevelCalibration = calibration; if (LevelCalibration == null) { LevelCalibration = new Calibration(); } // wire up our observable AnalogInputPort.Subscribe ( new FilterableChangeObserver <FloatChangeResult, float>( h => { var newWaterLevel = VoltageToWaterLevel(h.New); var oldWaterLevel = VoltageToWaterLevel(h.Old); WaterLevel = newWaterLevel; // save state RaiseEventsAndNotify ( new FloatChangeResult(newWaterLevel, oldWaterLevel) ); } ) ); }
/// <summary> /// Create a new ADXL337 sensor object. /// </summary> /// <param name="x">Analog pin connected to the X axis output from the ADXL377 sensor.</param> /// <param name="y">Analog pin connected to the Y axis output from the ADXL377 sensor.</param> /// <param name="z">Analog pin connected to the Z axis output from the ADXL377 sensor.</param> /// <param name="updateInterval">Update interval for the sensor, set to 0 to put the sensor in polling mode.</param> /// <<param name="accelerationChangeNotificationThreshold">Acceleration change threshold.</param> public Adxl377(IIODevice device, IPin x, IPin y, IPin z, ushort updateInterval = 100, double accelerationChangeNotificationThreshold = 0.1F) { if ((updateInterval != 0) && (updateInterval < MinimumPollingPeriod)) { throw new ArgumentOutOfRangeException(nameof(updateInterval), "Update interval should be 0 or greater than " + MinimumPollingPeriod); } _xPort = device.CreateAnalogInputPort(x); _yPort = device.CreateAnalogInputPort(y); _zPort = device.CreateAnalogInputPort(z); // // Now set the default calibration data. // XVoltsPerG = 0.00825; YVoltsPerG = 0.00825; ZVoltsPerG = 0.00825; SupplyVoltage = 3.3; if (updateInterval > 0) { var t = StartUpdating(); } else { Update().RunSynchronously(); } }
public AnalogReadApp() { Console.WriteLine("Starting App"); _a00 = Device.CreateAnalogInputPort(Device.Pins.A00); _a01 = Device.CreateAnalogInputPort(Device.Pins.A01); Console.WriteLine("Analog port created"); this.StartReading(); }
public void ConfigurePorts() { Console.WriteLine("Creating Outputs..."); _orangeLed = Device.CreateDigitalOutputPort(Device.Pins.D10); _speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D11)); _photoResistor = Device.CreateAnalogInputPort(Device.Pins.A00); _photoResistor.Changed += _photoResistor_Changed; }
public AnalogTemperature(IAnalogInputPort analogInputPort, KnownSensorType sensorType, Calibration calibration = null) { AnalogInputPort = analogInputPort; // // If the calibration object is null use the defaults for TMP35. // if (calibration == null) { calibration = new Calibration(); } switch (sensorType) { case KnownSensorType.TMP35: case KnownSensorType.LM35: case KnownSensorType.LM45: _yIntercept = 0; _millivoltsPerDegreeCentigrade = 10; break; case KnownSensorType.LM50: case KnownSensorType.TMP36: _yIntercept = 500; _millivoltsPerDegreeCentigrade = 10; break; case KnownSensorType.TMP37: _yIntercept = 0; _millivoltsPerDegreeCentigrade = 20; break; case KnownSensorType.Custom: _yIntercept = calibration.MillivoltsAtSampleReading - (calibration.SampleReading * calibration.MillivoltsPerDegreeCentigrade); _millivoltsPerDegreeCentigrade = calibration.MillivoltsPerDegreeCentigrade; break; default: throw new ArgumentException("Unknown sensor type", nameof(sensorType)); } // wire up our observable // have to convert from voltage to temp units for our consumers // this is where the magic is: this allows us to extend the IObservable // pattern through the sensor driver AnalogInputPort.Subscribe ( new FilterableObserver<FloatChangeResult, float>( h => { var newTemp = VoltageToTemperature(h.New); var oldTemp = VoltageToTemperature(h.Old); Temperature = newTemp; // save state RaiseEventsAndNotify ( new AtmosphericConditionChangeResult( new AtmosphericConditions(newTemp, 0, 0), new AtmosphericConditions(oldTemp, 0, 0) ) ); } ) ); }
/// <summary> /// Creates a FC28 soil moisture sensor object with the especified analog pin and digital pin. /// </summary> /// <param name="analogPort"></param> /// <param name="digitalPort"></param> public Fc28( IAnalogInputPort analogPort, IDigitalOutputPort digitalPort, float minimumVoltageCalibration = 0f, float maximumVoltageCalibration = 3.3f) { AnalogInputPort = analogPort; DigitalPort = digitalPort; MinimumVoltageCalibration = minimumVoltageCalibration; MaximumVoltageCalibration = maximumVoltageCalibration; }
/// <summary> /// Create a new ADXL337 sensor object. /// </summary> /// <param name="xPin">Analog pin connected to the X axis output from the ADXL337 sensor.</param> /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL337 sensor.</param> /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL337 sensor.</param> public Adxl337(IIODevice device, IPin xPin, IPin yPin, IPin zPin) { _xPort = device.CreateAnalogInputPort(xPin); _yPort = device.CreateAnalogInputPort(yPin); _zPort = device.CreateAnalogInputPort(zPin); // // Now set the default calibration data. // XVoltsPerG = 0.325f; YVoltsPerG = 0.325f; ZVoltsPerG = 0.550f; SupplyVoltage = 3.3f; }
public AnalogJoystick(IAnalogInputPort horizontalInputPort, IAnalogInputPort verticalInputPort, JoystickCalibration calibration = null) { this.HorizontalInputPort = horizontalInputPort; this.VerticalInputPort = verticalInputPort; if (calibration == null) { this.Calibration = new JoystickCalibration(); } else { this.Calibration = calibration; } }
public Ky038(IAnalogInputPort analogPort, IDigitalInputPort digitalInputPort) { this.analogPort = analogPort; this.digitalInputPort = digitalInputPort; digitalInputPort.Changed += DigitalInputPort_Changed; analogPort.StartSampling(); while (true) { Console.WriteLine($"Analog: {analogPort.Voltage}"); Thread.Sleep(250); } }
public AnalogJoystick(IAnalogInputPort horizontalInputPort, IAnalogInputPort verticalInputPort, JoystickCalibration calibration = null, bool isInverted = false) { HorizontalInputPort = horizontalInputPort; VerticalInputPort = verticalInputPort; IsInverted = isInverted; if (calibration == null) { Calibration = new JoystickCalibration(3.3f); } else { Calibration = calibration; } InitSubscriptions(); }
void Initialize() { Console.WriteLine("Initializing hardware..."); //==== create our analog input port analogIn = Device.CreateAnalogInputPort(Device.Pins.A00); //==== Classic .NET Events analogIn.Updated += (s, result) => { Console.WriteLine($"Analog event, new voltage: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V"); }; //==== Filterable Observable var observer = IAnalogInputPort.CreateObserver( handler: result => { Console.WriteLine($"Analog observer triggered; new: {result.New.Volts:n2}V, old: {result.Old?.Volts:n2}V"); }, // filter is optional. in this case, we're only notifying if the // voltage changes by at least `0.1V`. filter: result => { if (result.Old is { } oldValue) { return((result.New - oldValue).Abs().Volts > 0.1); }
public TMP36(IIODevice device, IPin pin) { analogPort = device.CreateAnalogInputPort(pin); }
/// <summary> /// Creates a Capacitive soil moisture sensor object with the especified AnalogInputPort. /// </summary> /// <param name="analogPort"></param> public Capacitive(IAnalogInputPort analogPort) { AnalogPort = analogPort; }
/// <summary> /// Creates a FC28 soil moisture sensor object with the especified analog pin and digital pin. /// </summary> /// <param name="analogPort"></param> /// <param name="digitalPort"></param> public FC28(IAnalogInputPort analogPort, IDigitalOutputPort digitalPort) { AnalogPort = analogPort; DigitalPort = digitalPort; }
/// <summary> /// Creates a new `WindVane` on the specified input port. Optionally, /// with a custom voltage to azimuth lookup. /// </summary> /// <param name="inputPort">The analog input.</param> /// <param name="azimuthVoltages">Optional. Supply if you have custom azimuth voltages.</param> public WindVane(IAnalogInputPort inputPort, IDictionary <float, Azimuth> azimuthVoltages = null) { this.AzimuthVoltages = azimuthVoltages; this.inputPort = inputPort; this.Init(); }
public Gp2D12(IIODevice device, IPin analogInputPin) { analogInputPort = device.CreateAnalogInputPort(analogInputPin); analogInputPort.Changed += AnalogInputPort_Changed; }
/// <summary> /// Create a new light sensor object using a static reference voltage. /// </summary> /// <param name="pin">AnalogChannel connected to the sensor.</param> public Temt6000(IIODevice device, IPin pin) { sensor = device.CreateAnalogInputPort(pin); }
public void InitializeIO() { _analogIn = Device.CreateAnalogInputPort(Device.Pins.A00); Console.WriteLine("Analog port created"); }
/// <summary> /// Create a new light sensor object using a dynaic reference voltage. /// </summary> /// <param name="pin">Analog channel connected to the sensor.</param> /// <param name="referenceVoltagePin">Analog channel connected to the reference voltage souce.</param> public ALSPT19315C(IIODevice device, IPin pin, IPin referenceVoltagePin) { _sensor = device.CreateAnalogInputPort(pin); _referenceVoltagePort = device.CreateAnalogInputPort(referenceVoltagePin); }
/// <summary> /// Create a new light sensor object using a static reference voltage. /// </summary> /// <param name="pin">AnalogChannel connected to the sensor.</param> /// <param name="referenceVoltage">Reference voltage.</param> public ALSPT19315C(IIODevice device, IPin pin, double referenceVoltage) { _sensor = device.CreateAnalogInputPort(pin); _referenceVoltagePort = null; _referenceVoltage = referenceVoltage; }
/// <summary> /// Create a new light sensor object using a static reference voltage. /// </summary> /// <param name="pin">AnalogChannel connected to the sensor.</param> public Alspt19315C(IIODevice device, IPin pin) { sensor = device.CreateAnalogInputPort(pin); }
public CapacitiveTouchScreen(IIODevice device, IPin pinXPos, IPin pinXNeg, IPin pinYPos, IPin pinYNeg) { portXNeg = device.CreateAnalogInputPort(pinXNeg); }
public AnalogTemperature(IAnalogInputPort analogInputPort, KnownSensorType sensorType, Calibration calibration = null) { AnalogInputPort = analogInputPort; switch (sensorType) { case KnownSensorType.TMP35: case KnownSensorType.LM35: case KnownSensorType.LM45: calibration = new Calibration( degreesCelciusSampleReading: 25, millivoltsAtSampleReading: 250, millivoltsPerDegreeCentigrade: 10); break; case KnownSensorType.LM50: case KnownSensorType.TMP36: calibration = new Calibration( degreesCelciusSampleReading: 25, millivoltsAtSampleReading: 750, millivoltsPerDegreeCentigrade: 10); break; case KnownSensorType.TMP37: calibration = new Calibration( degreesCelciusSampleReading: 25, millivoltsAtSampleReading: 750, millivoltsPerDegreeCentigrade: 10); break; case KnownSensorType.Custom: //user provided calibration break; default: calibration = new Calibration(); break; } SensorCalibration = calibration; // wire up our observable // have to convert from voltage to temp units for our consumers // this is where the magic is: this allows us to extend the IObservable // pattern through the sensor driver AnalogInputPort.Subscribe ( new FilterableChangeObserver <FloatChangeResult, float>( h => { var newTemp = VoltageToTemperature(h.New); var oldTemp = VoltageToTemperature(h.Old); Temperature = newTemp; // save state RaiseEventsAndNotify ( new AtmosphericConditionChangeResult( new AtmosphericConditions(newTemp, null, null), new AtmosphericConditions(oldTemp, null, null) ) ); } ) ); }