Ejemplo n.º 1
0
        private Mpl3115a2 mpl3115a2; // Altitue, pressure and temperature sensor

        /// <summary>
        /// Constructs WeatherShield with I2C bus and status LEDs identified
        /// </summary>
        /// <param name="i2cBusName"></param>
        /// <param name="ledBluePin"></param>
        /// <param name="ledGreenPin"></param>
        public WeatherShield(string i2cBusName, int ledBluePin, int ledGreenPin)
        {
            statusLedBluePin  = ledBluePin;
            statusLedGreenPin = ledGreenPin;
            htu21d            = new Htu21d(i2cBusName);
            mpl3115a2         = new Mpl3115a2(i2cBusName);
        }
Ejemplo n.º 2
0
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            // configure our BME280 on the I2C Bus
            var i2c = Device.CreateI2cBus();

            mpl3115A2 = new Mpl3115a2(i2c);

            // Example that uses an IObersvable subscription to only be notified
            // when the temperature changes by at least a degree, and humidty by 5%.
            // (blowing hot breath on the sensor should trigger)
            mpl3115A2.Subscribe(new FilterableObserver <AtmosphericConditionChangeResult, AtmosphericConditions>(
                                    h => {
                Console.WriteLine($"Temp and pressure changed by threshold; new temp: {h.New.Temperature}, old: {h.Old.Temperature}");
            },
                                    e =>
            {
                return
                (
                    (Math.Abs(e.Delta.Temperature.Value) > 1) &&
                    (Math.Abs(e.Delta.Pressure.Value) > 5)
                );
            }
                                    ));

            // classical .NET events can also be used:
            mpl3115A2.Updated += (object sender, AtmosphericConditionChangeResult e) =>
            {
                Console.WriteLine($"Temperature: {e.New.Temperature}C, Pressure: {e.New.Pressure}hPa");
            };

            // get an initial reading
            ReadConditions().Wait();

            Console.WriteLine("Begin updates");

            // start updating continuously
            mpl3115A2.StartUpdating();
        }