EtherMania.com.WeatherShield1.readAveragedValue C# (CSharp) Method

readAveragedValue() public method

public readAveragedValue ( units unitType ) : float
unitType units
return float
        public float readAveragedValue(units unitType)
        {
            float result = float.MinValue;
            commands command = commands.CMD_UNKNOWN;

            switch (unitType)
            {
                case units.TEMPERATURE:
                    command = commands.CMD_GETTEMP_C_AVG;
                    break;

                case units.HUMIDITY:
                    command = commands.CMD_GETHUM_AVG;
                    break;

                case units.PRESSURE:
                    command = commands.CMD_GETPRESS_AVG;
                    break;
            }

            sendCommand(command, 0);
            if (readAnswer(command))
                result = decodeFloatValue();

            return result;
        }

Usage Example

Example #1
0
        public static void Main()
        {
            // This is the main WeatherShield object
            WeatherShield1 wShield1 = new WeatherShield1(Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D2, WeatherShield1.DEFAULTADDRESS);

            // Wait until valid samples are ready on the shield
            while (!wShield1.averageValuesReady())
            {
                led.Write(true);
                Thread.Sleep(1000);
                led.Write(false);
                Thread.Sleep(1000);
            }

            // Then start sending data to Console
            while (true)
            {
                // Read values from the shield
                float temperature = wShield1.readAveragedValue(WeatherShield1.units.TEMPERATURE);
                float pressure = wShield1.readAveragedValue(WeatherShield1.units.PRESSURE);
                float humidity = wShield1.readAveragedValue(WeatherShield1.units.HUMIDITY);

                if ((temperature != float.MinValue) &&
                    (pressure != float.MinValue) &&
                    (humidity != float.MinValue))
                {
                    // Connection performed OK.
                    led.Write(true);

                    Debug.Print("Temperature: " + temperature.ToString() + "\n");
                    Debug.Print("Pressure: " + pressure.ToString() + "\n");
                    Debug.Print("Humidity: " + humidity.ToString() + "\n");

                    PachubeGlue pachube = new PachubeGlue(URL, keyAPI);
                    if (pachube.sendMeasures(pressure, temperature, humidity))
                        blinkLed();
                }
                else
                {
                    // Something went wrong
                    led.Write(false);

                    // Try to resync the WeatherShield connection
                    wShield1.resetConnection();
                }

                // Wait for 30 seconds
                Thread.Sleep(30000);
            }
        }
All Usage Examples Of EtherMania.com.WeatherShield1::readAveragedValue