public MeadowApp() { Console.WriteLine("Initializing..."); // configure our AnalogTemperature sensor analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); // Example that uses an IObersvable subscription to only be notified // when the temperature changes by at least a degree. analogTemperature.Subscribe(new FilterableObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( h => { Console.WriteLine($"Temp changed by a degree; new: {h.New.Temperature}, old: {h.Old.Temperature}"); }, e => { return(Math.Abs(e.Delta.Temperature) > 1); } )); // classical .NET events can also be used: analogTemperature.Updated += (object sender, AtmosphericConditionChangeResult e) => { Console.WriteLine($"Temp Changed, temp: {e.New.Temperature}°C"); }; // Get an initial reading. ReadTemp().Wait(); // Spin up the sampling thread so that events are raised and // IObservable notifications are sent. analogTemperature.StartUpdating(); }
public void ConfigurePorts() { temperatureSensor = new AnalogTemperature( Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35 ); // subscribe to 1/4º C changes in temp temperatureSensor.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( h => { // probably update screen or something Console.WriteLine($"Current Temp: {h.New.Temperature}ºC"); } /*, * e => { return (Math.Abs(e.Delta.Temperature) > 0.25f); }*/)); }
void Initialize() { Console.WriteLine("Initialize hardware..."); onboardLed = new RgbPwmLed(device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue, 3.3f, 3.3f, 3.3f, Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); onboardLed.SetColor(Color.Red); button = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp); button.Clicked += ButtonClicked; var config = new SpiClockConfiguration ( speedKHz: 6000, mode: SpiClockConfiguration.Mode.Mode3 ); var display = new St7789 ( device: Device, spiBus: Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config), chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240 ); displayController = new DisplayController(display); capacitive = new Capacitive( device: Device, analogPin: Device.Pins.A01, minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION, maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION); capacitive.Subscribe(new FilterableChangeObserver <FloatChangeResult, float>( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateMoistureImage(handler); displayController.UpdateMoisturePercentage(handler.New, handler.Old); onboardLed.SetColor(Color.Green); }, filter => { return(Math.Abs(filter.Delta) > 0.05); } )); capacitive.StartUpdating( sampleCount: 10, sampleIntervalDuration: 40, standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds); analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35); analogTemperature.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateTemperatureValue(handler.New.Temperature.Value, handler.Old.Temperature.Value); onboardLed.SetColor(Color.Green); }, filter => { return(Math.Abs(filter.Delta.Temperature.Value) > 1f); } )); analogTemperature.StartUpdating( sampleCount: 10, sampleIntervalDuration: 40, standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds); onboardLed.SetColor(Color.Green); }
void Initialize() { onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); button = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp); button.Clicked += ButtonClicked; var config = new SpiClockConfiguration( speed: new Frequency(48000, Frequency.UnitType.Kilohertz), mode: SpiClockConfiguration.Mode.Mode3); var spiBus = Device.CreateSpiBus( clock: Device.Pins.SCK, copi: Device.Pins.MOSI, cipo: Device.Pins.MISO, config: config); var display = new St7789 ( device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240 ); displayController = new DisplayController(display); capacitive = new Capacitive( device: Device, analogPin: Device.Pins.A01, minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION, maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION); var capacitiveObserver = Capacitive.CreateObserver( handler: result => { onboardLed.SetColor(Color.Purple); displayController.UpdateMoistureImage(result.New); displayController.UpdateMoisturePercentage(result.New, result.Old.Value); onboardLed.SetColor(Color.Green); }, filter: null ); capacitive.Subscribe(capacitiveObserver); capacitive.StartUpdating(TimeSpan.FromHours(1)); analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35); var analogTemperatureObserver = AnalogTemperature.CreateObserver( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateTemperatureValue(handler.New, handler.Old.Value); onboardLed.SetColor(Color.Green); }, filter: null ); analogTemperature.Subscribe(analogTemperatureObserver); analogTemperature.StartUpdating(TimeSpan.FromHours(1)); onboardLed.SetColor(Color.Green); }