#include "TM1637Display.h"
#define CLK 9
#define DIO 10
TM1637Display display = TM1637Display(CLK, DIO);
#include "FastLED.h"
#define NUM_LEDS 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
const int NEO = 3;
int num;
int num_pre;
int num_set;
int num_dis;
int num_out;
int num_sto;
int col;
int smooth;
int stor;
const int time_pot = A5;
const int button = 6;
int state;
int p;
void setup() {
Serial.begin(9600);
display.clear();
display.setBrightness(2);
FastLED.addLeds< LED_TYPE, NEO, COLOR_ORDER >(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
pixel(0, 0, 255);
pinMode(button, INPUT_PULLUP);
}
void loop() {
if (state == 0) {
pixel(0, 0, 255);
// select minutes 1-60
// wait for button
while (digitalRead(button) == HIGH) {
// smooth attempt uno
stor = 0;
for (smooth = 0; smooth < 10; smooth++) {
num = analogRead(time_pot);
stor = stor + num;
}
stor = stor / 10;
num_pre = map(stor, 1023, 0, 1, 60);
num_set = round(num_pre);
num_set = num_set * 100;
// smooth attempt dos
if (num_set != num_sto) {
display.showNumberDecEx(num_set, 0b01000000, false, 4, 0);
}
num_sto = num_set;
}
state = 1;
pixel(0, 0, 0);
} else if (state == 1) {
// minute count down
for (num_out = num_pre; num_out > 1; num_out--) {
num_dis = num_out * 100;
display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
delay(60000);
}
state = 2;
} else if (state == 2) {
// 60 second count down
for (num_dis = 60; num_dis > 0; num_dis--) {
display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
delay(1000);
}
state = 3;
} else if (state == 3) {
// warning
display.clear();
// wait for button
while (digitalRead(button) == HIGH) {
pixel(255, 0, 0);
delay(300);
pixel(0, 0, 0);
delay(300);
}
// sort-a debounce
pixel(0, 255, 0);
display.clear();
delay(1500);
state = 0;
num_sto = 0;
}
}
void pixel(int r, int g, int b) {
for (int w = 0; w < NUM_LEDS; w++) {
leds[w] = CRGB(r, g, b);
FastLED.show();
}
}