Electronic – arduino – How to get this to not read an arduino digital input

arduinocinputtoggle switch

I have been working on this for a while. It is a small part of a much bigger code.

I have a digital input pin connected to a on/off switch and another input pin connected to a momentary push button. For the momentary push button I am using the onebutton library. It works great.

I am trying to make it so the momentary push button does nothing unless the on off switch connected to a digital pin if switched on or HIGH. For some reason the momentary push button still gets read and my program runs regardless of whether the switch is swichted or not.

void loop()
{
    ignition_mode = digitalRead(ignition);
    if (ignition_mode == HIGH);
    {
        button.tick();
    }
}

Best Answer

If you format you code properly, you can see that it does not what you intended:

void loop()
{
  ignition_mode = digitalRead(ignition);
  if (ignition_mode == HIGH)
    ;  // empty statement which means that nothing is done if the condition is true
  { // new scope-block, which has quite no effect here
    button.tick();
  }
}

You most likely intended:

void loop()
{
  ignition_mode = digitalRead(ignition);
  if (ignition_mode == HIGH)
  { 
    button.tick();
  }
}