Ejemplo n.º 1
0
        public void ConversionRoundTrip()
        {
            ElectricResistance ohm = ElectricResistance.FromOhms(1);

            Assert.AreEqual(1, ElectricResistance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance);
            Assert.AreEqual(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance);
            Assert.AreEqual(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance);
        }
        public void ConversionRoundTrip()
        {
            ElectricResistance ohm = ElectricResistance.FromOhms(1);

            AssertEx.EqualTolerance(1, ElectricResistance.FromGigaohms(ohm.Gigaohms).Ohms, GigaohmsTolerance);
            AssertEx.EqualTolerance(1, ElectricResistance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance);
            AssertEx.EqualTolerance(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance);
            AssertEx.EqualTolerance(1, ElectricResistance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance);
            AssertEx.EqualTolerance(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            const ConnectorPin adcClock = ConnectorPin.P1Pin12;
            const ConnectorPin adcMiso  = ConnectorPin.P1Pin16;
            const ConnectorPin adcMosi  = ConnectorPin.P1Pin18;
            const ConnectorPin adcCs    = ConnectorPin.P1Pin22;

            Console.WriteLine("MCP-3008 Sample: Reading temperature on Channel 0 and luminosity on Channel 1");
            Console.WriteLine();
            Console.WriteLine("\tClock: {0}", adcClock);
            Console.WriteLine("\tCS: {0}", adcCs);
            Console.WriteLine("\tMOSI: {0}", adcMosi);
            Console.WriteLine("\tMISO: {0}", adcMiso);
            Console.WriteLine();

            ElectricPotential voltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            using (var adcConnection = new Mcp3008SpiConnection(
                       driver.Out(adcClock),
                       driver.Out(adcCs),
                       driver.In(adcMiso),
                       driver.Out(adcMosi)))
                using (var temperatureConnection = new Tmp36Connection(
                           adcConnection.In(Mcp3008Channel.Channel0),
                           voltage))
                    using (var lightConnection = new VariableResistiveDividerConnection(
                               adcConnection.In(Mcp3008Channel.Channel1),
                               ResistiveDivider.ForLowerResistor(ElectricResistance.FromKiloohms(10))))
                    {
                        Console.CursorVisible = false;

                        while (!Console.KeyAvailable)
                        {
                            var temperature = temperatureConnection.GetTemperature();
                            var resistor    = lightConnection.GetResistance();
                            var lux         = resistor.ToLux();

                            Console.WriteLine("Temperature = {0,5:0.0} °C\tLight = {1,5:0.0} Lux ({2} ohms)", temperature, lux, (int)resistor.Ohms);

                            Console.CursorTop--;

                            Thread.Sleep(1000);
                        }
                    }

            Console.CursorTop++;
            Console.CursorVisible = true;
        }
 /// <inheritdoc cref="ElectricResistance.FromKiloohms(double?)"/>
 public static ElectricResistance?Kiloohms(this decimal?value) => ElectricResistance.FromKiloohms(value == null ? (double?)null : Convert.ToDouble(value.Value));
 /// <inheritdoc cref="ElectricResistance.FromKiloohms(double)"/>
 public static ElectricResistance Kiloohms(this decimal value) => ElectricResistance.FromKiloohms(Convert.ToDouble(value));
 /// <inheritdoc cref="ElectricResistance.FromKiloohms(double?)"/>
 public static ElectricResistance?Kiloohms(this float?value) => ElectricResistance.FromKiloohms(value);
 /// <inheritdoc cref="ElectricResistance.FromKiloohms(double)"/>
 public static ElectricResistance Kiloohms(this double value) => ElectricResistance.FromKiloohms(value);
Ejemplo n.º 8
0
 public void NumberToKiloohmsTest() =>
 Assert.Equal(ElectricResistance.FromKiloohms(2), 2.Kiloohms());
Ejemplo n.º 9
0
 public static ElectricResistance?Kiloohms <T>(this T?value) where T : struct => ElectricResistance.FromKiloohms(value == null ? (double?)null : Convert.ToDouble(value.Value));
 public static ElectricResistance Kiloohms <T>(this T value) =>
 ElectricResistance.FromKiloohms(Convert.ToDecimal(value));