• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Gpio.GpioPin类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Windows.Devices.Gpio.GpioPin的典型用法代码示例。如果您正苦于以下问题:C# GpioPin类的具体用法?C# GpioPin怎么用?C# GpioPin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GpioPin类属于Windows.Devices.Gpio命名空间,在下文中一共展示了GpioPin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Init

        public override void Init()
        {
            Debug.WriteLine("Initializing push button.");

            try
            {
                _pushButtonPin = _gpioController.OpenPin(Pin);

                if (_pushButtonPin == null)
                {
                    Debug.WriteLine(string.Format("Push button pin not found at GPIO {0}.", Pin));
                    throw new Exception(string.Format("Push button pin not found at GPIO {0}.", Pin));
                }
                else
                {
                    Debug.WriteLine(string.Format("Push button initialized at GPIO {0}.", Pin));
                }

                if (_pushButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                else
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.Input);

                _pushButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

                _pushButtonPin.ValueChanged += _pushButtonPin_ValueChanged;

                Debug.WriteLine("Push button initialized.");
            }
            catch
            {
                Debug.WriteLine("Failed to initialize push button.");
                throw new Exception("Failed to initialize push button.");
            }
        }
开发者ID:adgroc,项目名称:win-iot-core,代码行数:35,代码来源:PushButton.cs


示例2: InitGPIO

        private void InitGPIO()
        {
            var mygpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (mygpio == null)
            {
                buttonPin = null;
                ledPin = null;
                return;
            }
            ledPin = mygpio.OpenPin(LEDPINNBR);
            ledPin.Write(GpioPinValue.Low); //initialize Led to On as wired in active Low config (+3.3-Led-GPIO)
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            buttonPin = mygpio.OpenPin(BUTTONPINNBR);
            //buttonPin.Write(GpioPinValue.High);
            //buttonPin.SetDriveMode(GpioPinDriveMode.Output);
            //buttonPinValCurrent = buttonPin.Read();
            buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            //buttonPinValPrior = GpioPinValue.High;

            Debug.WriteLine("ButtonPin Value at Init: " + buttonPin.Read() + ",      with Pin ID = " + buttonPin.PinNumber);

            //buttonPinVal = buttonPin.Read();
            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(20);

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPressAction;
        }
开发者ID:dettwild,项目名称:ButtonCLickBG,代码行数:32,代码来源:StartupTask.cs


示例3: pin_ValueChanged

        private async void pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
                if (args.Edge.CompareTo(GpioPinEdge.RisingEdge) == 0)
                {
                    //Motion Detected UI
                    UiAlert();

                    //Create JSON payload
                    var json = string.Format("{{sensor:Motion,  room:MsConfRoom1,  utc:{0}}}", DateTime.UtcNow.ToString("MM/dd/yyyy_HH:mm:ss"));
                    var data = new ASCIIEncoding().GetBytes(json);

                    //POST Data
                    string url = "https://rrpiot.azurewebsites.net/SensorData";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST";
                    request.ContentType = "application/json";
                    using (Stream myStream = await request.GetRequestStreamAsync())
                    {
                        myStream.Write(data, 0, data.Length);
                    }
                    await request.GetResponseAsync();
                }
                else
                {
                    //Display No Motion Detected UI
                    UiNoMotion();
                }

        }
开发者ID:RandyPatterson,项目名称:MotionDetector,代码行数:29,代码来源:MainPage.xaml.cs


示例4: InitGPIO

        private void InitGPIO()
        {
            // Initialize the GPIO controller
            GpioController gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _pin1 = null;
                _pin2 = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            // Initialize the GPIO pin for the first LED
            _pin1 = gpio.OpenPin(LED1_PIN);
            _pin1.Write(GpioPinValue.Low);
            _pin1.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize the LED1 Ellipse to draw Gray
            LED1.Fill = _grayBrush;

            // Initialize the GPIO pin for the second LED
            _pin2 = gpio.OpenPin(LED2_PIN);
            _pin2.Write(GpioPinValue.Low);
            _pin2.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize the LED2 Ellipse to draw Gray
            LED2.Fill = _grayBrush;

            // Show the GPIO is OK message
            GpioStatus.Text = "GPIO pin initialized correctly.";
        }
开发者ID:mort8088,项目名称:Windows-IoT-Tutorials,代码行数:33,代码来源:MainPage.xaml.cs


示例5: InitGPIO

        private void InitGPIO()
        {
            GpioController gpio = null;
            try
            {
                gpio = GpioController.GetDefault();
            }
            catch (Exception e)
            {
                GpioStatus.Text = e.Message;
            }

            if (gpio == null)
            {
                _pin = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            _pin = gpio.OpenPin(LED_PIN);
            _pinValue = GpioPinValue.High;
            _pin.Write(_pinValue);
            _pin.SetDriveMode(GpioPinDriveMode.Output);

            GpioStatus.Text = "GPIO pin intitialized correctly.";
        }
开发者ID:fr3gu,项目名称:Nascon.Blinky,代码行数:26,代码来源:MainPage.xaml.cs


示例6: InputPin_ValueChanged

 private void InputPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if(args.Edge == GpioPinEdge.FallingEdge)
     {
         AccumulatedTotal = AccumulatedTotal + LitersPerPulse;
     }
 }
开发者ID:AerialBreakSoftware,项目名称:Win10RaspberrySprinkle,代码行数:7,代码来源:FlowMeter.cs


示例7: InitializeGpio

        private void InitializeGpio()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);

            if ( buttonPin == null)
            {
                GpioStatus.Text = "Unable to open button pin.";
                return;
            }

            // Button is in a active high configuration which means it will go to high when pressed
            // Take advantage of the Raspberry Pi's built in pull down resistors
            buttonPin.SetDriveMode(GpioPinDriveMode.InputPullDown);

            // Set a debounce timeout to filter out the ups and downs from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event - aka when the button is pushed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
开发者ID:tyeth,项目名称:Christmas-List,代码行数:30,代码来源:MainPage.xaml.cs


示例8: InitGPIO

        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // error prompt
            if (gpio == null) {
                GpioStatus.Text = "There's no GPIO controller on this device";
                return -1;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledPin = gpio.OpenPin(LED_PIN);

            // init LED to OFF by HIGH, cuz LED is wired in LOW config
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            // checking if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // setting debounce timeout
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // register for ValueChanged event
            // so buttonPin_ValueChanged()
            // is called when button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly";
        }
开发者ID:btlone,项目名称:Quiet-Maker,代码行数:35,代码来源:PushButton.cs


示例9: ValueChangedHandler

        private void ValueChangedHandler(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            var pinNumber = sender.PinNumber;
            var gpioPinValue = sender.Read();
            Debug.WriteLine("Pin {0} changed to {1}", pinNumber, gpioPinValue);

            if (pinNumber == TiltSensorPin)
            {
                _halper.DishwasherTilt(gpioPinValue == GpioPinValue.High);
                var currentStatus = _halper.Get().CurrentStatus;
                if (currentStatus == DishwasherStatus.Clean && gpioPinValue == GpioPinValue.High)
                {
                    ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(10000));
                }
                return;
            }

            var tiltSensorValue = _gpioSensors[TiltSensorPin].Read();
            if (gpioPinValue == GpioPinValue.High)
            {
                if (pinNumber == CleanLightPin)
                {
                    _halper.EndDishwasherRun();
                }
                else if (tiltSensorValue == GpioPinValue.Low && _pinToCycleTypeMap.ContainsKey(pinNumber))
                {
                    _halper.StartDishwasherRun(_pinToCycleTypeMap[pinNumber]);
                }
            }
        }
开发者ID:ChrisMancini,项目名称:DishwasherMonitor,代码行数:30,代码来源:GpioMonitor.cs


示例10: AddPin

 public void AddPin(int pinNumber, GpioPin pin)
 {
     lock (m_pinMap)
     {
         m_pinMap[pin.PinNumber] = pin;
     }
 }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:7,代码来源:GpioPinEventListener.cs


示例11: Run

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            //Motor starts off
            currentPulseWidth = 0;

            //The stopwatch will be used to precisely time calls to pulse the motor.
            stopwatch = Stopwatch.StartNew();

            GpioController controller = GpioController.GetDefault();

            //Buttons are attached to pins 5 and 6 to control which direction the motor should run in
            //Interrupts (ValueChanged) events are used to notify this app when the buttons are pressed
            forwardButton = controller.OpenPin(5);
            forwardButton.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 250);
            forwardButton.SetDriveMode(GpioPinDriveMode.Input);
            forwardButton.ValueChanged += _forwardButton_ValueChanged;

            backwardButton = controller.OpenPin(6);
            backwardButton.SetDriveMode(GpioPinDriveMode.Input);
            forwardButton.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 250);
            backwardButton.ValueChanged += _backgwardButton_ValueChanged;


            servoPin = controller.OpenPin(13);
            servoPin.SetDriveMode(GpioPinDriveMode.Output);

            
           

            //You do not need to await this, as your goal is to have this run for the lifetime of the application
            Windows.System.Threading.ThreadPool.RunAsync(this.MotorThread, Windows.System.Threading.WorkItemPriority.High);
        }
开发者ID:EBailey67,项目名称:samples,代码行数:34,代码来源:StartupTask.cs


示例12: InitGpio

        /// <summary>
        /// 
        /// </summary>
        private void InitGpio()
        {
            var gpio = GpioController.GetDefault();
            if (gpio== null)
            {
                Debug.WriteLine("Can't find GpioController.");
                return;
            }

            pin = gpio.OpenPin(inputPin);

            if (pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                pin.SetDriveMode(GpioPinDriveMode.Input);
            }

            Debug.WriteLine("GPIO initializing...");

            //Sleep
            for (int i = 0; i <= 10000; i++) { }

            //Event
            pin.ValueChanged += Pin_ValueChanged;

            Debug.WriteLine("GPIO initialized.");
        }
开发者ID:linyixian,项目名称:SecurityWebcam,代码行数:33,代码来源:MainPage.xaml.cs


示例13: InitGPIO

        private void InitGPIO()
        {
            if (!ApiInformation.IsTypePresent(GpioPresentNS))
            {
                return;
            }

            var gpio = GpioController.GetDefault();
            if (gpio == null)
            {
                Debug.WriteLine("There is no GPIO controller on this device.");
                return;
            }

            var buttonPin = gpio.OpenPin(ButtonPin);
            ledPin = gpio.OpenPin(LedPin);

            // Initialize LED to the OFF state by first writing a HIGH value
            // We write HIGH because the LED is wired in a active LOW configuration
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(100);

            buttonPin.ValueChanged += ButtonPin_ValueChanged;
        }
开发者ID:DotNETForDevices,项目名称:IoTSamples,代码行数:33,代码来源:MainPage.xaml.cs


示例14: MainPage

        public MainPage()
        {
            this.InitializeComponent();

            // call the method to initialize variables and hardware components
            InitHardware();

            // set interval of timer to 1 second
            _dispatchTimer.Interval = TimeSpan.FromSeconds(1);

            // invoke a method at each tick (as per interval of your timer)
            _dispatchTimer.Tick += _dispatchTimer_Tick;

            // initialize pin (GPIO pin on which you have set your temperature sensor)
            _temperaturePin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);

            // create instance of a DHT11 
            _dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);

            // start the timer
            _dispatchTimer.Start();

            // set start date time
            _startedAt = DateTimeOffset.Now;
        }
开发者ID:romilbheda,项目名称:Azure-IoT-Hub-Temperature-Sensors,代码行数:25,代码来源:MainPage.xaml.cs


示例15: Initialize

        /// <summary>
        ///   Initializes SPI connection and control pins
        /// </summary>
        public void Initialize(SpiMode spiMode, int chipSelectPin, int chipEnablePin, int interruptPin)
        {
            var gpio = GpioController.GetDefault();
            // Chip Select : Active Low
            // Clock : Active High, Data clocked in on rising edge
            _spiDevice = InitSpi(chipSelectPin, spiMode).Result;

            _irqPin = gpio.OpenPin(interruptPin);
            _irqPin.SetDriveMode(GpioPinDriveMode.InputPullUp);

            // Initialize IRQ Port
            // _irqPin = new InterruptPort(interruptPin, false, Port.ResistorMode.PullUp,
            //                            Port.InterruptMode.InterruptEdgeLow);
            _irqPin.ValueChanged += _irqPin_ValueChanged;

            _cePin = gpio.OpenPin(chipEnablePin);
            // Initialize Chip Enable Port
            _cePin.SetDriveMode(GpioPinDriveMode.Output);

            // Module reset time
            var task = Task.Delay(100);
            task.Wait();

            _initialized = true;
        }
开发者ID:HouseOfTheFuture,项目名称:IoT-Device,代码行数:28,代码来源:NRF24L01Plus.cs


示例16: InitAsync

        public async Task InitAsync()
        {
            if (!init)
            {
                var gpio = GpioController.GetDefault();

                if (gpio != null)
                {
                    gpioPinTrig = gpio.OpenPin(trigGpioPin);
                    gpioPinEcho = gpio.OpenPin(echoGpioPin);
                    gpioPinTrig.SetDriveMode(GpioPinDriveMode.Output);
                    gpioPinEcho.SetDriveMode(GpioPinDriveMode.Input);
                    gpioPinTrig.Write(GpioPinValue.Low);

                    //first time ensure the pin is low and wait two seconds
                    gpioPinTrig.Write(GpioPinValue.Low);
                    await Task.Delay(2000);
                    init = true;
                }
                else
                {
                    throw new InvalidOperationException("Gpio not present");
                }
            }
        }
开发者ID:jmservera,项目名称:Rover,代码行数:25,代码来源:UltrasonicDistanceSensor.cs


示例17: IOProvider

        public IOProvider(Container container)
        {
            m_Container = container;

            if (m_Controller != null)
            {
                m_NextPagePin = m_Controller.OpenPin(NextPagePin);
                m_NextSubRedditPin = m_Controller.OpenPin(NextSubRedditPin);
                m_ShutdownPin = m_Controller.OpenPin(ShutdownPin);
            }

            if (m_ShutdownPin != null)
            {
                m_ShutdownPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                m_ShutdownPin.DebounceTimeout = DebounceTimeout;
                m_ShutdownPin.ValueChanged += InputValueChanged;
            }

            if (m_NextPagePin != null)
            {
                m_NextPagePin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                m_NextPagePin.DebounceTimeout = DebounceTimeout;
                m_NextPagePin.ValueChanged += InputValueChanged;
            }

            if (m_NextSubRedditPin != null)
            {
                m_NextSubRedditPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                m_NextSubRedditPin.DebounceTimeout = DebounceTimeout;
                m_NextSubRedditPin.ValueChanged += InputValueChanged;
            }
        }
开发者ID:LokiFaun,项目名称:Windows_IoT,代码行数:32,代码来源:IOProvider.cs


示例18: PulseIn

        private double PulseIn(GpioPin echoPin, GpioPinValue value)
        {
            var t = Task.Run(() =>
            {
                //Recieve pusle
                while (this.echoPin.Read() != value)
                {
                }
                timeWatcher.Start();

                while (this.echoPin.Read() == value)
                {
                }
                timeWatcher.Stop();
                //Calculating distance
                double distance = timeWatcher.Elapsed.TotalSeconds * 17000;
                return distance;
            });
            bool didComplete = t.Wait(TimeSpan.FromMilliseconds(100));
            if(didComplete)
            {
                return t.Result;
            }
            else
            {
                return 0.0;                
            }
        }
开发者ID:farukc,项目名称:MTPSolution,代码行数:28,代码来源:HCSR04.cs


示例19: InitGPIO

 private void InitGPIO()
 {
     var gpio = GpioController.GetDefault();
     _pinMotion = gpio.OpenPin(LED_MOTION);
     _pinMotion.SetDriveMode(GpioPinDriveMode.Input);
     _pinMotion.ValueChanged += _pinMotion_ValueChanged;
 }
开发者ID:yudhistre,项目名称:LNM-DX-People-Counter,代码行数:7,代码来源:MainPage.xaml.cs


示例20: MotionSensor

 public MotionSensor()
 {
     var gpioController = GpioController.GetDefault();
     motionSensorPin = gpioController.OpenPin(App.Controller.XmlSettings.GpioMotionPin);
     motionSensorPin.SetDriveMode(GpioPinDriveMode.Input);
     motionSensorPin.ValueChanged += MotionSensorPin_ValueChanged;
 }
开发者ID:jadeiceman,项目名称:securitysystem-1,代码行数:7,代码来源:MotionSensor.cs



注:本文中的Windows.Devices.Gpio.GpioPin类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Gpio.GpioPinValueChangedEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# Geolocation.PositionChangedEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap