Community

PushButton Missing First Event

Hello,
I’m going throug some example projects for Arduinos and at the same time am doing them on my Meadow F7 Micro v1.d
I’m trying to use a simple push button to toggle a LED and seem to be missing the first event after starting up. My code and wiring is attached.

using System;
using System.Threading;
using Meadow;
using Meadow.Devices;
using Meadow.Foundation;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Buttons;
using Mono.CodeGeneration;

namespace debounce
{
    public class MeadowApp : App<F7Micro, MeadowApp>
    {
        Led led;
        PushButton button; 

        /// <summary>
        /// constructor
        /// </summary>
        public MeadowApp()
        {
            Initialize();
            Thread.Sleep(Timeout.Infinite);
        }

        /// <summary>
        /// initialize hardware
        /// </summary>
        void Initialize()
        {
            Console.WriteLine("Initialize hardware start...");
            led = new Led(Device.CreateDigitalOutputPort(Device.Pins.D09));
            led.IsOn = false;
            button = new PushButton(Device, Device.Pins.D02,Meadow.Hardware.ResistorMode.Disabled,5);  // debounce for 5ms
            //button = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D02),Meadow.Hardware.ResistorMode.Disabled,5);  // debounce for 5ms
            button.Clicked += ButtonClicked;
            Console.WriteLine("Initialize hardware end...");
        }

        /// <summary>
        /// toggle the state of the LED
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ButtonClicked(object sender, EventArgs e)
        {
            Console.WriteLine("Toggling LED from " + led.IsOn + " to " + !led.IsOn);
            led.IsOn = !led.IsOn;
        }
    }
}

Do I have a wiring or logic issue?

There is a reported issue where the first interrupt can take a while to be generated see issue #74.

Are you seeing this delay rather than the issue going missing ?

Regards,
Mark