#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" not sure how you would do it, this doesn't work
// sevseg.setBrightness(displayOff ? 90 : 0);
// delay(300);
}
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;
}
}
}