InterruptPort issue

I have a bumper (see image) in my Cerbuino Bee.
I had it implemented as InterruptPort but now every time I click it it exits the program. In debug mode it doesn’t enter the event.


private static InterruptPort rightMoustache;

private static void moustache_OnInterruptRight(uint port, uint state, DateTime time)
        {
            Debug.Print("Bigode Direito");
            rightMoustache.ClearInterrupt();
        }

public static void Main()
        {

            Debug.Print("Start");
            const Cpu.Pin rightMoustachePin = FEZCerbuino.Pin.Digital.D10;

            rightMoustache = new InterruptPort(rightMoustachePin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            
            rightMoustache.OnInterrupt += moustache_OnInterruptRight;


Either create you app using Gadgeteer

or

Add



at the end of Main routine
1 Like

This how i would do it using a Gadgeteer project…

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp1
{
    public partial class Program
    {
        private InterruptPort _rightMoustache;  
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            _rightMoustache = new InterruptPort(GHI.Hardware.FEZCerb.Pin.PA15,true,Port.ResistorMode.PullUp,Port.InterruptMode.InterruptEdgeLow);
            _rightMoustache.OnInterrupt += rightMoustache_OnInterrupt;
        }

        void rightMoustache_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print("Bigode Direito");             
            _rightMoustache.ClearInterrupt(); 
        }
    }
}
1 Like

It worked! Thanks @ Bill Gates

I’m using a NETMF project and I’m using 2 bumpers to decide the behaviour used by the robot.

@ codewizpt - yr welcome, look forward to seeing the robot :slight_smile:

Another option, if your device is battery powered you might want to put the processor to sleep when you’re not using it…

while (true)
{
Microsoft.SPOT.Hardware.PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.GeneralPurpose);
}

Your device will automatically wake up instantly when the interrupt fires. You shouldn’t notice a difference in performance but you will save some battery power.

1 Like

Thanks, untitled. I will try, though I have a LiPo battery :wink: