Shortened code for TM1637 scoreboard

I recently created a smart dartboard for an independent study that automatically updates the score when a target is triggered. I believe the code I created is more efficient than others in the library. Let me know if it works for you.

#include <TM1637Display.h>

#define CLK_PIN 2 // Define CLK pin for TM1637 display
#define DIO_PIN 3 // Define DIO pin for TM1637 display
#define BUTTON_PIN_ONE 4 // Define button pin
#define BUTTON_PIN_TWO 5 // Define button pin

TM1637Display display(CLK_PIN, DIO_PIN);

int scoreOne = 0; // Initial score
int scoreTwo = 0;

void setup() {
pinMode(BUTTON_PIN_ONE, INPUT_PULLUP); // Set button pin as input with pull-up resistor
pinMode(BUTTON_PIN_TWO, INPUT_PULLUP); // Set button pin as input with pull-up resistor
display.setBrightness(0x0f); // Set display brightness (0-7), adjust as needed
display.showNumberDec(0000); // Display initial score
Serial.println("Welcome to Smart Dart");
}

void loop() {
if (digitalRead(BUTTON_PIN_ONE) == LOW) { // Check if the button is pressed
delay(50); // Debounce delay
scoreOne++; // Increment the score // Update the display with the new score
delay(500); // Optional delay to avoid multiple increments from a single press
}

if (digitalRead(BUTTON_PIN_TWO) == LOW) { // Check if the decrease button is pressed
delay(50); // Debounce delay
scoreTwo++; // Decrement the score // Update the display with the new score
delay(500); // Optional delay to avoid multiple decrements from a single press
}
display.showNumberDec(scoreTwo * 100 + scoreOne);
}

Your topic has been moved as it does not indicate a problem with the Arduino CLI.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will apply code tags which makes the code easier to read and copy and the forum software will display it correctly.

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