M6Gpower
Posts: 1
Joined: Mon Mar 05, 2018 4:52 pm

Problem with Interrupt

Mon Mar 05, 2018 5:41 pm

Hi everyone , i am trying to increment a variable everytime the Hallsensor detects the magnet but its not working . I am very new in the field windows iot c# with raspi 3.


So my code looks like:

Code: Select all

public sealed partial class MainPage : Page
    {


        private int count = 5;
        private const int SENSOR_PIN = 5; //SENSOR PIN
        private GpioPin sensorPin; 

        public MainPage()
        {

            this.InitializeComponent();
            InitGPIO(); 
        }


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

            if (gpio == null)
            {
                GpioStatus.Text = "No Gpio Pins!";
                return;
            }

            sensorPin = gpio.OpenPin(SENSOR_PIN);
            sensorPin.SetDriveMode(GpioPinDriveMode.Input);
            sensorPin.ValueChanged += sensorPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";

        }

        //INTERRUPT HANDLER
        private void sensorPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            // Increment 
            if (e.Edge == GpioPinEdge.FallingEdge)
            {
                count++;
            }
        }
    } 
} 



Return to “Windows 10 for IoT”

Who is online

Users browsing this forum: No registered users and 2 guests