Still working on double dice

Why is this working WITHOUT the "while" statement? If I touch ANY pin to ground , the dice (display) roll and stop and remain when pin not connected? The button does not even need to be given a pin number and while statement not needed. Trying to get 2 dice to roll on my nano with a TM1637, 4 segment display with a photocell for a button.
No other wiring than four TM1637 pins and ground any other pin on nano.

#include <TM1637.h>
//using nano with button between 8 and ground
//declare pins
int CLK = 2;
int DIO = 3;
int button = A2;

TM1637 tm(CLK, DIO);

void setup() {

  pinMode(button, INPUT);

  //initialize TM1637 seven segment display;set brightness; 0-7
  tm.set(2);
  tm.init();
}

void loop() {

  // while   (    digitalRead(button));
  tm.display(0, random(1, 7));

  delay(50);

  //while (    digitalRead(button));
  tm.display(3, random(1, 7));
}
```Thanks again for any help
Greg

Interesting description but you are describing a hardware problem without an annotated schematic this is difficult to solve. Links to the hardware items will help us help you, be sure they have technical information.

after you sort out your mystery, you'll probably want to configure the input as INPUT_PULLUP to enable the internal pull-up resistor.

Please add a photo of your setup as well.
Your problem may also be that your schematic is different from your real setup...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.