/// <summary> /// Get the current temperature and update the Temperature property. /// </summary> public void Update() { var reading = (float)(AnalogPort.Read() * 3300); reading -= _yIntercept; reading /= _millivoltsPerDegreeCentigrade; Temperature = reading; }
/// <summary> /// Returns the soil moisture current value. /// </summary> /// <returns>Value ranges from 0 - 100</returns> public async Task <float> Read() { DigitalPort.State = true; Thread.Sleep(5); var sample = AnalogPort.Read(); DigitalPort.State = false; Moisture = 100 - Map(sample, 0, 1023, 0, 100); return(Moisture); }
public double Read(AnalogPort analogPort) { byte register = (byte)analogPort; register += RegisterValueBase; byte[] writeBuffer = new byte[1] { register }; byte[] readBuffer = new byte[2] { 0, 0 }; Debug.Assert(Device != null, "Initialise method not called"); Device.WriteRead(writeBuffer, readBuffer); ushort value = BitConverter.ToUInt16(readBuffer, 0); Debug.WriteLine($"GroveBaseHatRPI Read {analogPort} MSB 0x{readBuffer[1]:X} LSB 0x{readBuffer[0]:X} Value {value}"); return((double)value / 10.0); }
/// <summary> /// Returns the soil moisture current value. /// </summary> /// <returns>Value ranges from 0 - 100</returns> public async Task <float> Read() { Moisture = AnalogPort.Read(); return(100 - Map(Moisture, 0, 1023, 0, 100)); }
/// <summary> /// Implement IDisposable interface. /// </summary> public void Dispose() { AnalogPort.Dispose(); AnalogPort = null; }