Problems with a PIP-Boy code

Hi there! I recently made something to resemble the PIP-Boy from Fallout. A PIP-Boy, for the uninitiated, is a wearable portable computer resembling a watch. The chasis is done and the LCD looks great, but the MomentaryButton is causing problems. It doesn't work, but strangely, if I move the connections a bit, it performs the instructions for the first button (PIN_BUTTON).
Here's the code. Maybe you can change the MomentaryButton library with something more useful.

https://docs.google.com/document/d/1e-7zKGzl7lw-wyx8tbyrtfVOirOgI1xicm3EsOLPJwI/edit?usp=sharing

The code is too big to post here.

Haven't opened up the link to stare at your code,
but jiggling wires causing a change in button read state sounds like a button that isn't using a pullup resistor, so it floats haphazardly.

I don't know if this is the main cause but I noticed you don't use buttonX.setup() as indicated here

You should make a version with a loop that just keeps the check() and the if/else logic for wasClicked() wasHeld() and have it print on serial monitor stuff like

if (button1.wasClicked() {
 Serial.println ("button1 was clicked"); 
} else ..
..

or just insert Serial.println() after each if/else case to see in serial monitor if the buttons are read correctly.

You have to debug/test the clicking/holding button logic that drives the loop() conditional cases

All those long statements in loop if/else blocks should have their own separated functions to have a better view on loop() button logic flow.

PS it is important to call buttonX.setup() for each buttonX in setup(), because it activates internal pull-up on those pins.

Hi,

Here's the code. Maybe you can change the MomentaryButton library with something more useful.

https://docs.google.com/document/d/1e-7zKGzl7lw-wyx8tbyrtfVOirOgI1xicm3EsOLPJwI/edit?usp=sharing

The code is too big to post here.

If you use REPLY rather then QUICK REPLY you will find an ATTACHMENT button.
Also can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

The suggestion about needing a pullup or pulldown resistor is a very valid one.

Tom... :slight_smile:

Thanks for your help so far, but now I got another problem. I dumped the MomentaryButton library and tried to use what Arduino natively gives me. This time, if I ask Arduino to do X if the voltage is HIGH on the button, it will do X even if I'm not pressing it. If I ask it to do X if the voltage is LOW, it won't do anything no matter how much or how long I press.

Code:

Code

P.S. I am not using a pullup rezistor because it work just perfect with Arduino Uno, but I need it working with NANO as well.

Hi,
If you use REPLY rather then QUICK REPLY you will find an ATTACHMENT button.
Attach the ino file, please.
Also can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Some forum members are using platforms that do not like going to clouds and other file locations.

Thanks .. Tom... :slight_smile:

I attached the code.
There simply would be no use in drawing a wiring layout, as the buttons are the only problems. This is the keypad I'm using : Membrane 1x4 Keypad
The Keypad's GND wire is connected to...well..GND on the Arduino Nano, and the 2nd button's wire is connected to PB2 (or the pin marked "D10" on Arduino Nano).
Thanks again for your help :slight_smile:

SurviveBoy.ino (11.2 KB)

Hi,
If you are switching digital input to gnd, what is the input doing when you are not pressing the button?
I looked in your setup, and you do not have pullups turned on for your button inputs.

The digital inputs are high impedance and if not connected to gnd or 5V they float, and can have a 0 or 1 value at any time.

Either fit 10K pullup resistors to each of your buttons or turn on the internal pullup on your digital inputs.

Tom... :slight_smile: