示例#1
0
        public double GetDistanceFromSensor(string measure = "cm")
        {
            Thread.Sleep(3);
            OutputPin.Write(State.High);
            Thread.Sleep(1);
            OutputPin.Write(State.Low);

            while (inputPin.Read() == "0")
            {
                NoSignal = DateTime.Now.Ticks;
            }
            while (inputPin.Read() == "1")
            {
                Signal = DateTime.Now.Ticks;
            }

            var    tickDiff = Signal - NoSignal;
            double distance;

            if (measure == "cm")
            {
                distance = tickDiff / 0.000058;
            }
            else if (measure == "in")
            {
                distance = tickDiff / 0.000148;
            }
            else
            {
                Console.WriteLine("Improper choice of measurement: in or cm");
                distance = 0;
            }

            return(distance);
        }
示例#2
0
        public static void TestGpio()
        {
            var pin11 = new OutputGpioPin(GpioPinNumber.Gpio11);
            var pin2  = new OutputGpioPin(GpioPinNumber.Gpio17);

            var pin4 = new InputGpioPin(GpioPinNumber.Gpio4);

            pin4.Read();

            Console.WriteLine("Press ESC to stop");

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                pin11.Write(State.Low);
                Console.WriteLine("Pin 11 : " + pin11.State);
                pin2.Write(State.High);
                Console.WriteLine("Pin 2 : " + pin2.State);
                Thread.Sleep(750);
                pin11.Write(State.High);
                Console.WriteLine("Pin 11 : " + pin11.State);
                pin2.Write(State.Low);
                Console.WriteLine("Pin 2 : " + pin2.State);
                Thread.Sleep(750);
            }


            pin11.Cleanup();
            pin2.Cleanup();
        }
示例#3
0
 public bool CheckSensor()
 {
     if (inputPin.Read() == "1")
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }