- I used single PIR sensor for detecting the motion of the object, for that I wrote the GPIOValueChagendEvent, but this event will only
triggered whenever the PIR motion sensor value changed.
The ValueChanged event of the general-purpose I/O(GPIO) occurs when the value of pin changes, either because of an external stimulus when the pin is configured as an input, or when a value is written to the pin when the pin in configured as an output.
- But if I have two PIR sensors is it possible to write the one more GPIOValueChangedEvent. If yes, can you elaborate how to write the
sample code using C#
Yes, it is possible to do that. Please refer to following code with using PirSensor Class.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var pirS1 = new PirSensor(17, PirSensor.SensorType.ActiveHigh);
pirS1.motionDetected += new EventHandler<Windows.Devices.Gpio.GpioPinValueChangedEventArgs>(OnPirSensor1MotionDetected);
var pirS2 = new PirSensor(27, PirSensor.SensorType.ActiveHigh);
pirS2.motionDetected += new EventHandler<Windows.Devices.Gpio.GpioPinValueChangedEventArgs>(OnPirSensor2MotionDetected);
}
private async void OnPirSensor1MotionDetected(object sender, Windows.Devices.Gpio.GpioPinValueChangedEventArgs earg)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
pirSensorVal1.Text = earg.Edge.ToString();
});
}
private async void OnPirSensor2MotionDetected(object sender, Windows.Devices.Gpio.GpioPinValueChangedEventArgs earg)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
pirSensorVal2.Text = earg.Edge.ToString();
});
}
- Suppose if two PIR sensors will detected the motion of the object at the same time then what happens.
If the two PIR sensors detect the motion, the event of motionDetected will be invoked for each other.