Countdown Game Buzzer project using TM1637 display

Hi everybody, I have a 3d printed game buzzer project that I'm trying to achieve.
I'm using an arduino Nano where I connected a TM1637 display, 3 different buttons and a passive buzzer.

The goal of the project. When we turn on the game buzzer, READY should be display on the TM1637
Then if the button A is pressed a 30 seconds countdown is running and a tic-tac sound is running and if possible accelerates when we're approaching 0.

If the top button is pressed the countdown is stopped and the remaining time is displayed for like 3 seconds and we go back to the READY screen.

When the button B is pressed a 15seconds countdown is running and same as buttonA, a tic-tac sound is running and accelerates. But this time when the topButton is pressed the countdown is going back to 15seconds.

In both cases if the countdown is reaching 0 the buzzer should do a game over sound and the display blinks for 3 seconds.
And we can back to the READY screen after this.

With the code below, the part with the buttons and countdowns are running as expected. The parts that are missing are, the READY screen, the passive buzzer sound and the blinking display.

Let me know if you have some ideas

Thank you very much

#include <TM1637Display.h>
#include "Button.h"
// Define the pins for TM1637 display and buttons
const int CLK_PIN = 2;
const int DIO_PIN = 3;
const int BUZZER_PIN = 5; // Define buzzer pin
Button thirtySecButton = 4;
Button fifteenSecButton = 5;
Button topButton = 8;

TM1637Display display(CLK_PIN, DIO_PIN);

const uint8_t textread[] = {
  SEG_E | SEG_G,                                   // r
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D,           // E
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_G | SEG_C,   // A
  SEG_E | SEG_G | SEG_D | SEG_C | SEG_B            // d
};

const uint8_t texteady[] = {
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D,           // E
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_G | SEG_C,   // A
  SEG_E | SEG_G | SEG_D | SEG_C | SEG_B,            // d
  SEG_F | SEG_G | SEG_B | SEG_C | SEG_D            // y
};

const uint8_t textady[] = {
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_G | SEG_C,   // A
  SEG_E | SEG_G | SEG_D | SEG_C | SEG_B,           // d
  SEG_F | SEG_G | SEG_B | SEG_C | SEG_D,           // y
  SEG_D                                            //_
};

const uint8_t textdyr[] = {
  SEG_E | SEG_G | SEG_D | SEG_C | SEG_B,            // d
  SEG_F | SEG_G | SEG_B | SEG_C | SEG_D,            // y
  SEG_D,                                           //_
  SEG_E | SEG_G,                                   // r
};

const uint8_t textyre[] = {
  SEG_F | SEG_G | SEG_B | SEG_C | SEG_D,            // y
  SEG_D,                                           //_
  SEG_E | SEG_G,                                   // r
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D           // E
};

const uint8_t textrea[] = {
  SEG_D,                                           //_
  SEG_E | SEG_G,                                   // r
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D,           // E
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_G | SEG_C   // A
};

enum Mode {
  countdown30,
  countdown15,
  stopped,
  timeOut,
};

Mode mode = timeOut;

void setup() {
  display.setBrightness(1); // Set the brightness of the display (0 to 7)

  //setup buttons
  thirtySecButton.begin();
  fifteenSecButton.begin();
  topButton.begin();

}

void loop() {
  static unsigned long timer = millis();
  static int currentDisplayTime = 0;
  bool displayOff = false;

  if(thirtySecButton.pressed()) {
    timer = millis();
    currentDisplayTime = 300;
    mode = countdown30;
  }
  if(fifteenSecButton.pressed()) {
    timer = millis();
    currentDisplayTime = 150;
    mode = countdown15;
  }
  if(topButton.pressed()) {
    switch (mode) {
      case countdown30:
        mode = stopped;
        break;
      case countdown15:
        currentDisplayTime = 150;
        break;
    }
  }

  if(mode == stopped) {
      // toggle display "blink"
  }

  else if((millis() - timer >= 100)) {
    if(currentDisplayTime > 0) {
      timer += 100;
      display.showNumberDecEx(currentDisplayTime, 0b01000000, true, 3, 0);

      currentDisplayTime -= 1;
    }
    else {
     display.showNumberDecEx(0, 0b01000000, true, 4, 0);
      mode = timeOut;
    }
  }

}

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