// arduino stand timer ii
// vgmlr
#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;
const int time_pot = A5;
const int button = 6;
const int vibrate = 11;
const int photo = A3;
int state;
int up;
int more;
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);
pinMode(vibrate, OUTPUT);
digitalWrite(vibrate, LOW);
}
void loop() {
if (state == 0) {
// select minutes 1-60
// wait for button
while (digitalRead(button) == HIGH) {
num = analogRead(time_pot);
num_pre = map(num, 1023, 0, 1, 30);
num_set = round(num_pre);
num_set = num_set * 100;
display.showNumberDecEx(num_set, 0b01000000, false, 4, 0);
}
num_sto = num_pre;
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
pixel(255, 0, 0);
display.clear();
alert();
// standing limit
pixel(0, 0, 255);
display.showNumberDecEx(100, 0b01000000, false, 4, 0);
delay(1000);
for (num_dis = 59; num_dis > 0; num_dis--) {
display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
delay(500);
photo_read();
if (more == 0) {
while (more == 0) {
// no cheating
alert();
}
}
}
// wait for reset
photo_read();
pixel(0, 255, 0);
num_pre = num_sto;
num_dis = num_pre * 100;
display.showNumberDecEx(num_dis, 0b01000000, false, 4, 0);
while (more > 0) {
photo_read();
}
state = 1;
pixel(0, 0, 0);
} else {
// ayh
}
}
void alert() {
photo_read();
while (more == 0) {
digitalWrite(vibrate, HIGH);
delay(1000);
digitalWrite(vibrate, LOW);
delay(500);
photo_read();
}
}
void photo_read() {
up = 0;
more = 0;
for (p = 0; p < 20; p++) {
up = analogRead(photo);
more = more + up;
delay(25);
}
}
void pixel(int r, int g, int b) {
for (int w = 0; w < NUM_LEDS; w++) {
leds[w] = CRGB (r, g, b);
FastLED.show();
}
}