Stopwatch with tm1637

hi, i have a quostion, this code for a stopwacth with TM1637 is not working, sometimes it is just counting al the time or it stays at 1. could someone help me to solve it?

//#include <Arduino.h>
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK_TM 2
#define DIO_TM 3

// The amount of time (in milliseconds) between tests
#define TEST_DELAY   2000

const int bouton = 4;
const int buttonPin2 = 6;
const uint8_t SEG_DONE[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_C | SEG_E | SEG_G,                           // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
};

TM1637Display display(CLK_TM, DIO_TM);


int etatBouton,k,test,buttonState2;
 
void setup()
{
pinMode(bouton, INPUT); 
etatBouton = 0;
buttonState2=1;
test=0;
k=0;
display.setBrightness(7);
}
 
void loop()
{ etatBouton = digitalRead(bouton);

  bool lz = true;
if(etatBouton == HIGH) {
 k++;
    display.showNumberDec(k, lz);
    delay(1000);
  }

}

Check your physical connections are good and your power supply stable. Press on a few components while running. Does it stabilize?

please cut/paste your formatted
code into a code block using "</>"
as it is easier to read,
thank you)

I suggest that you study a little bit how for-loops work; this does not make sense.

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code (e.g. the [] instead of []).

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the IDE 1.x category.

it's missing ";" in the end.

...which means we're not looking at the actual sketch, since that would not compile.

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