Help with Digital Input (Button mode)

Hi,

I want to connect a button between 5v & D05 for example,
(I will also add a pull down resistor to drain the pin once I leave the button).
in order to set D15(Output) state as true once I press the button.

I used the interrupt code but I don’t want it to act as interrupt,
I want D15 to return to original state once I leave the button of D05.

Should I use while loop ?
someone have similar code to share ?

Thanks !

Hi @yuvi105

Based of your explanation

  • You want a push button connected on D05
  • When button is pressed → D15 digital output is set to true
  • When button is release → D15 digital output is set back to false

Am i understanding this correctly?

If im right, you could simply add event handlers on the PushButton and do something like this:

IDigitalOutputPort port;
PushButton button;

public MeadowApp()
{
    port = Device.CreateDigitalOutputPort(Device.Pins.D15, false);

    button = new PushButton(Device, Device.Pins.D05);
    button.PressStarted += ButtonUp_PressStarted;
    button.PressEnded += Button_PressEnded;
}

private void ButtonUp_PressStarted(object sender, EventArgs e)
{
    port.State = true;
}

private void Button_PressEnded(object sender, EventArgs e)
{
    port.State = false;
}

let me know if any of that helps.

Thanks,
Jorge

Thanks a lot Jorge !

That’s exactly what I meant, and it works !

Appreciate it.