You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • I'd say:

    • Take your buttons, and connect one side of each to 3.3v
    • Connect the other side of each to a spare IO
    • For each button, add the command pinMode(BTN_PIN, "input_pulldown")

    Now, you could use setWatch to call when something happens, but as you're making a game chances are you have a function that gets called each frame. If so, you might want to do something like:

    var BTN = { LEFT: A5, RIGHT: A6, FIRE: A7 };
    pinMode(BTN.LEFT, "input_pulldown");
    pinMode(BTN.RIGHT "input_pulldown");
    pinMode(BTN.FIRE, "input_pulldown");
    
    function onFrame() {
      if (BTN.LEFT.read());  // go left
      if (BTN.RIGHT.read());  // go right
      if (BTN.FIRE.read());  // fire!
    }
    
  • I'd do it the other way - set the pins input_pullup, and wait for them to go low, rather than high, and connect the other side of the button to ground instead of 3v3. Better practice to do it like this since you don't have to run the power rail all over hell (and you're already running ground all over hell), and a short involving Vcc is likely to be worse than a short involving Gnd.

    You'll find that this is almost always how non-matrix'ed buttons are done in commercial products. Also more generally applicable, since many micros only have pullups built-in, no pulldowns.

About

Avatar for DrAzzy @DrAzzy started