Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

One InterruptPort, two interrupts?


  • Please log in to reply
4 replies to this topic

#1 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2015 - 02:02 PM

Dear friends,

 

I want to detect both ON and OFF states of a GPIO pin by means of interrupts.  Ideally, this would involve one event handler for ON (triggered by InterruptMode.InterruptEdgeLevelHigh) and a separate handler for  OFF (InterruptMode.InterruptEdgeLevelLow).  I looks like Netduino doesn't allow attaching two handlers to one pin.  Port.InterruptMode.InterruptEdgeBoth might work but then how would I know whether the pin went high or low?

 

Suggestions?



#2 Juzzer

Juzzer

    Advanced Member

  • Members
  • PipPipPip
  • 135 posts
  • LocationHertfordshire, UK

Posted 28 March 2015 - 04:08 PM

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using StmHelper;
 
namespace MFConsoleApplication1
{
    public class Program
    {
        private static InterruptPort _pin;
        
        public static void Main()
        {
            _pin = new InterruptPort(Pin.PC1,true,Port.ResistorMode.PullUp,Port.InterruptMode.InterruptEdgeBoth);
            _pin.OnInterrupt += pin_OnInterrupt;
            Thread.Sleep(Timeout.Infinite);
        }
 
        static void pin_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            PinState buttonState = _pin.Read() ? PinState.Off : PinState.On;
            switch (buttonState)
            {
                case PinState.Off:
                   Debug.Print("Off");
                    break;
                case PinState.On:
                   Debug.Print("On");
                    break;
            }
        }
    }
    public enum PinState
    {
        Off = 0,
        On = 1
    }
}


#3 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2015 - 06:03 PM

Thanks for the quick reply.  I should have thought about reading the pin itself... makes perfect sense.



#4 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2015 - 09:44 PM

As far as I can tell, PinState is not well documented.  Try Googling Netduino PimState and you'll see what I mean.



#5 nlsa

nlsa

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2015 - 09:45 PM

Oh, Lord, please let me take back that last post.  






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.