#include <Wire.h>
#include "DS1307.h"
#include <GyverOLED.h>
//#include <EncButton.h>
#include <EncButton2.h>
#include <TimerMs.h>
#include "buildTime.h"
//GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
DS1307 clock;
// подключаем кнопки на пины D2 и D3
EncButton2<EB_BTN> btn_up(INPUT, 2);
EncButton2<EB_BTN> btn_down(INPUT, 3);
// (период, мс), (0 не запущен / 1 запущен), (режим: 0 период / 1 таймер)
TimerMs tmr_charging(300, 1, 1);
TimerMs tmr_screen(5000, 1, 1);
TimerMs tmr_menu(10000, 0, 1);
TimerMs tmr_stopwatch(120000, 0, 1);
TimerMs tmr_alarm(1000, 1, 1);
uint8_t charging_animation = 0, alarm_hour = 24, alarm_minute = 24;
int chargerPin = 4, chargerPin_done = 5, vibrationPin = 6, battery = 25;
bool charging, charging_done, battery_setting = true, screen_status = true, alarm_status = false;
//int t = 0;
const uint8_t bat25_27x11[] PROGMEM = {
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x07, 0x04, 0xFC, 0x07, 0x04, 0x05,
0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x07, 0x01, 0x01
};
const uint8_t bat50_27x11[] PROGMEM = {
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x07, 0x04, 0xFC, 0x07, 0x04, 0x05,
0x05, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x07, 0x01, 0x01
};
const uint8_t bat75_27x11[] PROGMEM = {
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01,
0x01, 0x01, 0x01, 0x01, 0x07, 0x04, 0xFC, 0x07, 0x04, 0x05,
0x05, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05,
0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04,
0x04, 0x07, 0x01, 0x01
};
const uint8_t bat100_27x11[] PROGMEM = {
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0x01,
0xFD, 0xFD, 0xFD, 0x71, 0x77, 0x04, 0xFC, 0x07, 0x04, 0x05,
0x05, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05,
0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x05, 0x05, 0x05,
0x04, 0x07, 0x01, 0x01
};
const uint8_t bat_done_27x11[] PROGMEM = {
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD,
0xFD, 0xFD, 0xFD, 0x71, 0x77, 0x04, 0xFC, 0x07, 0x04, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x04, 0x07, 0x01, 0x01
};
const uint8_t alarm_7x8[] PROGMEM = {
0x60, 0x7C, 0x7E, 0xFF, 0x7E, 0x7C, 0x60
};
void setup() {
//Serial.begin(9600);
clock.begin();
clock.fillByYMD(BUILD_YEAR, BUILD_MONTH, BUILD_DAY);
clock.fillByHMS(BUILD_HOUR, BUILD_MIN, BUILD_SEC);
clock.fillDayOfWeek(SUN);
// установка времени и даты вручную, уберите /* */ и задайте числа
/*
clock.fillByYMD(2022, 6, 20); // год, месяц, дата
clock.fillByHMS(15, 28, 30); // часы, минуты, секунды
clock.fillDayOfWeek(SAT);
/*MON - Понедельник
TUE - Вторник
WED - Среда
THU - Четверг
FRI - Пяница
SAT - Суббота
SUN - Воскресенье
*/
clock.setTime(); // запись времени
oled.init(); // инициализация дисплея
pinMode(chargerPin, INPUT);
pinMode(chargerPin_done, INPUT);
pinMode(vibrationPin, OUTPUT);
tmr_charging.setPeriodMode();
tmr_screen.setTimerMode();
tmr_menu.setTimerMode();
tmr_stopwatch.setTimerMode();
tmr_alarm.setPeriodMode();
}
void loop() {
if ((tmr_screen.tick()) && (screen_status == true) ) {
screen_status = false;
oled.clear();
oled.update();
oled.setPower(screen_status);
}
btn_up.tick();
btn_down.tick();
// клик по любой из кнопке - включает экран
if (((btn_up.click()) || (btn_down.click())) && (screen_status == false)) {
screen_status = true;
oled.setPower(screen_status);
tmr_screen.start();
}
if (screen_status == true) {
main_screen();
}
// удержание верхней кнопки включает будильник
if ((btn_up.held()) && (screen_status == true)) {
if (alarm_status == true) {
alarm_status = false;
oled.clear(1 ,1, 7, 8);
} else {
alarm_status = true;
}
}
// удержание нижней кнопки открывает меню
if ((btn_down.held()) && (screen_status == true)) {
menu();
}
if (alarm_status == true) {
alarm_check();
}
}
void main_screen() {
clock.getTime();
//oled.clear(); // очистка дисплея
oled.setScale(3); // масштаб текста (1..4)
//oled.home(); // курсор в 0,0
oled.setCursor(16, 2);
if (clock.hour < 10) {
oled.print("0");
}
oled.print(clock.hour, DEC);
oled.print(":");
if (clock.minute < 10) {
oled.print("0");
}
oled.print(clock.minute, DEC);
//oled.print(":");
//oled.print(clock.second, DEC);
oled.setCursor(32, 5);
oled.setScale(1);
oled.print(clock.dayOfMonth, DEC);
oled.print(".");
oled.print(clock.month, DEC);
//oled.print(".");
//oled.print(clock.year + 2000, DEC);
oled.setCursor(68, 5);
//oled.setScale(1);
switch (clock.dayOfWeek) { // День недели
case MON:
oled.print("ПНД"); // "MON"
break;
case TUE:
oled.print("ВТР"); // "TUE"
break;
case WED:
oled.print("СРД"); // "WED"
break;
case THU:
oled.print("ЧТВ"); // "THU"
break;
case FRI:
oled.print("ПТН"); // "FRI"
break;
case SAT:
oled.print("СБТ"); // "SAT"
break;
case SUN:
oled.print("ВСК"); // "SUN"
break;
}
if (alarm_status == true) {
//oled.setCursorXY(1, 1);
oled.drawBitmap(1, 1, alarm_7x8, 7, 8, BITMAP_NORMAL, BUF_ADD);
}
charging = digitalRead(chargerPin);
charging_done = digitalRead(chargerPin_done);
//Serial.print("Зарядка идет - ");
//Serial.println(charging);
//Serial.print("Зарядка закончилась - ");
//Serial.println(charging_done);
if ((charging == true) && (charging_done == false)) {
if (tmr_charging.tick()) {
switch (charging_animation) {
case 0:
oled.clear(100, 1, 126, 11);
oled.drawBitmap(100, 1, bat25_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 1:
oled.drawBitmap(100, 1, bat50_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 2:
oled.drawBitmap(100, 1, bat75_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 3:
oled.drawBitmap(100, 1, bat100_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation = 0;
break;
}
}
}
if ((charging == true) && (charging_done == true)) {
oled.drawBitmap(100, 1, bat_done_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
}
if ((charging == false) && (charging_done == false)) {
if (charging_animation > 0) {
charging_animation = 0;
}
oled.clear(100, 1, 126, 11);
if (battery > 75) {
oled.drawBitmap(100, 1, bat100_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery > 50) {
oled.drawBitmap(100, 1, bat75_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery > 25) {
oled.drawBitmap(100, 1, bat50_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery >= 0) {
oled.drawBitmap(100, 1, bat25_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
}
}
oled.update();
//t = t+1;
//Serial.println(t);
}
void menu() {
tmr_menu.start();
oled.clear();
uint8_t menu_choice = 1;
bool back = false; // костыль, который появился из-за появившегося бага в пункте будильника, почему-то стало игнорировать таймер выхода, либо не полностью выходить из циклов
while (true) {
btn_up.tick();
btn_down.tick();
//Serial.print("таймер - ");
//Serial.println(tmr_menu.tick());
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
break;
}
if (btn_up.click()) {
tmr_menu.start();
menu_choice -= 1;
oled.clear();
if (menu_choice < 1 ) {
menu_choice = 5;
}
}
if (btn_down.click()) {
tmr_menu.start();
menu_choice += 1;
oled.clear();
if (menu_choice > 5) {
menu_choice = 1;
}
}
if (btn_up.held()) {
oled.clear();
tmr_screen.start();
break;
}
switch (menu_choice) {
case 1: // Фонарик
oled.setCursor(55, 0);
oled.setScale(1);
oled.print("Меню");
oled.setCursor(0, 1);
oled.setScale(2);
oled.print("Фонарик");
oled.setScale(1);
oled.setCursor(0, 3);
oled.print("Секундомер");
oled.setCursor(0, 4);
oled.print("Таймер");
oled.setCursor(0, 5);
oled.print("Будильник");
oled.setCursor(0, 6);
oled.print("Настройки");
if (btn_down.held()) {
oled.clear();
bool light = true;
long done = 1800000; // сек до отключения
while (true) {
btn_up.tick();
btn_down.tick();
if ((btn_up.click()) || (btn_down.click()) || (btn_up.held()) || (btn_down.held()) || (done == 0)) {
oled.clear();
tmr_menu.start();
break;
}
if (tmr_alarm.tick()) {
done -= 1;
}
if (light == true) {
oled.rect(0, 0, 128, 64);
light = false;
oled.update();
}
}
}
oled.update();
break;
case 2: // Секундомер
oled.setCursor(55, 0);
oled.setScale(1);
oled.print("Меню");
oled.setCursor(0, 1);
oled.print("Фонарик");
oled.setCursor(0, 2);
oled.setScale(2);
oled.print("Секундомер");
oled.setScale(1);
oled.setCursor(0, 4);
oled.print("Таймер");
oled.setCursor(0, 5);
oled.print("Будильник");
oled.setCursor(0, 6);
oled.print("Настройки");
if (btn_down.held()) {
oled.clear();
bool stopwatch_status = false;
int hour = 0, minute = 0, second = 0, second_real, difference;
oled.setScale(3);
tmr_stopwatch.start();
while (true) {
btn_up.tick();
btn_down.tick();
if ((tmr_stopwatch.tick()) && (stopwatch_status == false)) {
break;
}
if ((btn_up.click()) || (btn_down.click())) {
tmr_stopwatch.start();
if (stopwatch_status == false) {
stopwatch_status = true;
clock.getTime();
second_real = clock.second;
} else {
stopwatch_status = false;
}
}
if (btn_up.held()) {
tmr_menu.start();
oled.clear();
break;
}
if (btn_down.held()) {
if (stopwatch_status == true) {
stopwatch_status = false;
tmr_stopwatch.start();
}
hour = 0;
minute = 0;
second = 0;
oled.clear();
}
if (stopwatch_status == true) {
clock.getTime();
difference = second_real - clock.second;
if (difference != 0) {
second += 1;
}
second_real = clock.second;
if (second > 59) {
minute += 1;
second = 0;
oled.clear();
}
if (minute > 59) {
hour += 1;
minute = 0;
oled.clear();
}
if (hour > 9) {
oled.clear();
break;
}
}
oled.setCursor(1, 2);
oled.print(hour, DEC);
oled.print(":");
oled.print(minute, DEC);
oled.print(":");
oled.print(second, DEC);
oled.update();
}
}
oled.update();
break;
case 3: // Таймер
oled.setCursor(55, 0);
oled.setScale(1);
oled.print("Меню");
oled.setCursor(0, 1);
oled.print("Фонарик");
oled.setCursor(0, 2);
oled.print("Секундомер");
oled.setCursor(0, 3);
oled.setScale(2);
oled.print("Таймер");
oled.setScale(1);
oled.setCursor(0, 5);
oled.print("Будильник");
oled.setCursor(0, 6);
oled.print("Настройки");
if (btn_down.held()) {
oled.clear();
uint8_t choice = 1;
int minute = 0, second = 0, second_real, difference, minute_, second_;
tmr_stopwatch.start();
while (true) {
btn_up.tick();
btn_down.tick();
oled.setScale(3);
if (tmr_stopwatch.tick()) {
break;
}
if (btn_up.held()) {
tmr_menu.start();
oled.clear();
break;
}
if (btn_down.held()) {
tmr_stopwatch.tick();
oled.clear();
choice += 1;
}
if (choice > 3) {
choice = 1;
}
if (choice < 1) {
choice = 3;
}
switch (choice) {
case 1: // Минуты
if (btn_up.click()) {
tmr_stopwatch.tick();
minute += 1;
}
if (btn_down.click()) {
tmr_stopwatch.tick();
minute -= 1;
}
if (minute > 60) {
minute = 0;
}
if (minute < 0) {
minute = 60;
}
oled.setCursor(1, 3);
oled.print("__");
break;
case 2: // Секунды
if (btn_up.click()) {
tmr_stopwatch.tick();
second += 1;
}
if (btn_down.click()) {
tmr_stopwatch.tick();
second -= 1;
}
if (second > 59) {
second = 0;
}
if (second < 0) {
second = 59;
}
oled.setCursor(1, 3);
oled.print(" __");
break;
case 3: // Старт
if (((minute > 0) || (second > 0)) && ((btn_up.click()) || (btn_down.click()))) {
minute_ = minute;
if (minute == 0) {
second_ = second + 1;
} else {
second_ = second;
}
uint8_t timer_done = 30; // сек до завершения
while (true) {
btn_up.tick();
btn_down.tick();
if ((btn_up.held()) || (btn_down.held()) || (timer_done == 0)) {
digitalWrite(vibrationPin, LOW);
second_real = 0;
tmr_stopwatch.tick();
oled.clear();
break;
}
clock.getTime();
difference = second_real - clock.second;
if (difference != 0) {
second_ -= 1;
}
second_real = clock.second;
if (second_ < 0) {
minute_ -= 1;
if (minute_ < 0) {
second_ = 0;
} else {
second_ = 59;
}
}
if (minute_ < 0) {
if (tmr_alarm.tick()) {
digitalWrite(vibrationPin, HIGH);
timer_done -= 1;
} else {
digitalWrite(vibrationPin, LOW);
}
}
oled.setScale(3);
oled.setCursor(1, 2);
if (minute_ < 10) {
oled.print("0");
}
if (minute_ < 0) {
oled.print("0");
} else {
oled.print(minute_, DEC);
}
oled.print(":");
if (second_ < 10) {
oled.print("0");
}
oled.print(second_, DEC);
oled.setScale(1);
oled.setCursor(88, 3);
oled.print(" Стоп ");
oled.setCursor(88, 4);
oled.print(" ____ ");
oled.update();
}
}
oled.setScale(1);
oled.setCursor(88, 4);
oled.print(" _____");
oled.setScale(3);
break;
}
oled.setCursor(1, 2);
if (minute < 10) {
oled.print("0");
}
oled.print(minute, DEC);
oled.print(":");
if (second < 10) {
oled.print("0");
}
oled.print(second, DEC);
oled.setScale(1);
oled.setCursor(88, 3);
oled.print(" Старт");
oled.update();
}
}
oled.update();
break;
case 4: // Будильник
oled.setCursor(55, 0);
oled.setScale(1);
oled.print("Меню");
oled.setCursor(0, 1);
oled.print("Фонарик");
oled.setCursor(0, 2);
oled.print("Секундомер");
oled.setCursor(0, 3);
oled.print("Таймер");
oled.setCursor(0, 4);
oled.setScale(2);
oled.print("Будильник");
oled.setCursor(0, 6);
oled.setScale(1);
oled.print("Настройки");
if (btn_down.held()) {
tmr_menu.start();
oled.clear();
oled.setScale(3);
oled.setCursor(16, 2);
int alarm_hour_, alarm_minute_;
bool choice = true;
if ((alarm_hour == 24) && (alarm_minute == 24)) {
clock.getTime();
alarm_hour_ = clock.hour;
alarm_minute_ = clock.minute;
} else {
alarm_hour_ = alarm_hour;
alarm_minute_ = alarm_minute;
}
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
//tmr_menu.force();
break;
}
btn_up.tick();
btn_down.tick();
if ((btn_up.click()) || (btn_down.click())) {
tmr_menu.start();
if (choice == true) {
choice = false;
} else {
choice = true;
}
oled.clear();
}
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
oled.setCursor(3, 0);
oled.setScale(1);
oled.print("Установка будильника");
switch (choice) {
case true: // статус будильника
if (btn_down.held()) {
if (alarm_status == true) {
alarm_status = false;
} else {
alarm_status = true;
}
tmr_menu.start();
}
oled.setScale(2);
oled.setCursor(0, 1);
if (alarm_status == true) {
oled.print("ВКЛ ");
} else {
oled.print("ВЫКЛ");
}
oled.setScale(1);
oled.setCursor(0, 3);
if (alarm_hour_ < 10) {
oled.print("0");
}
oled.print(alarm_hour_);
oled.print(":");
if (alarm_minute_ < 10) {
oled.print("0");
}
oled.print(alarm_minute_);
break;
case false: // установка будильника
oled.setScale(1);
oled.setCursor(0, 1);
if (alarm_status == true) {
oled.print("ВКЛ ");
} else {
oled.print("ВЫКЛ");
}
oled.setScale(2);
oled.setCursor(0, 2);
if (alarm_hour_ < 10) {
oled.print("0");
}
oled.print(alarm_hour_);
oled.print(":");
if (alarm_minute_ < 10) {
oled.print("0");
}
oled.print(alarm_minute_);
if (btn_down.held()) {
tmr_menu.start();
oled.clear();
oled.setCursor(3, 0);
oled.setScale(1);
oled.print("Установка будильника");
oled.setScale(1);
oled.setCursor(0, 1);
if (alarm_status == true) {
oled.print("ВКЛ ");
} else {
oled.print("ВЫКЛ");
}
bool choice_ = true;
while (true) {
if (tmr_menu.tick()) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.held()) {
oled.clear();
alarm_hour = alarm_hour_;
alarm_minute = alarm_minute_;
tmr_menu.start();
break;
}
if (btn_down.held()) {
if (choice_ == true) {
choice_ = false;
} else {
choice_ = true;
}
tmr_menu.start();
}
oled.setScale(2);
oled.setCursor(30, 2);
if (alarm_hour_ < 10) {
oled.print("0");
}
oled.print(alarm_hour_);
oled.print(":");
if (alarm_minute_ < 10) {
oled.print("0");
}
oled.print(alarm_minute_);
oled.setScale(2);
oled.setCursor(30, 4);
switch (choice_) {
case true:
if (btn_up.click()) {
tmr_menu.start();
alarm_hour_ += 1;
}
if (btn_down.click()) {
tmr_menu.start();
alarm_hour_ -= 1;
}
if (alarm_hour_ > 23) {
alarm_hour_ = 0;
}
if (alarm_hour_ < 0) {
alarm_hour_ = 23;
}
oled.print("__ ");
break;
case false:
if (btn_up.click()) {
tmr_menu.start();
alarm_minute_ += 1;
}
if (btn_down.click()) {
tmr_menu.start();
alarm_minute_ -= 1;
}
if (alarm_minute_ > 59) {
alarm_minute_ = 0;
}
if (alarm_minute_ < 0) {
alarm_minute_ = 59;
}
oled.print(" __");
break;
}
oled.update();
}
}
break;
}
oled.update();
}
}
oled.update();
break;
case 5: // Настройки
oled.setCursor(55, 0);
oled.setScale(1);
oled.print("Меню");
oled.setCursor(0, 1);
oled.print("Фонарик");
oled.setCursor(0, 2);
oled.print("Секундомер");
oled.setCursor(0, 3);
oled.print("Таймер");
oled.setCursor(0, 4);
oled.print("Будильник");
oled.setCursor(0, 5);
oled.setScale(2);
oled.print("Настройки");
oled.setScale(1);
if (btn_down.held()) {
oled.clear();
tmr_screen.start();
uint8_t choice = 1;
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.click()) {
tmr_menu.start();
choice -= 1;
oled.clear();
if (choice < 1 ) {
choice = 3;
}
}
if (btn_down.click()) {
tmr_menu.start();
choice += 1;
oled.clear();
if (choice > 3 ) {
choice = 1;
}
}
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
switch (choice) {
case 1: // Язык
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Настройки");
oled.setCursor(0, 1);
oled.setScale(2);
oled.print("Язык");
oled.setCursor(0, 3);
oled.setScale(1);
oled.print("Дата/время");
oled.setCursor(0, 4);
oled.print("Батарея");
if (btn_down.held()) {
oled.clear();
tmr_screen.start();
}
break;
case 2: // Дата/время
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Настройки");
oled.setCursor(0, 1);
oled.print("Язык");
oled.setCursor(0, 2);
oled.setScale(2);
oled.print("Дата/время");
oled.setCursor(0, 4);
oled.setScale(1);
oled.print("Батарея");
if (btn_down.held()) {
oled.clear();
tmr_menu.start();
uint8_t choice_ = 1;
int day, month, year, hour, minute;
clock.getTime();
day = clock.dayOfMonth;
month = clock.month;
year = clock.year + 2000;
hour = clock.hour;
minute = clock.minute;
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.click()) {
tmr_menu.start();
oled.clear();
choice_ -= 1;
if (choice_ < 1 ) {
choice_ = 3;
}
}
if (btn_down.click()) {
tmr_menu.start();
oled.clear();
choice_ += 1;
if (choice_ > 3 ) {
choice_ = 1;
}
}
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Дата/Время");
oled.setCursor(0, 1);
switch (choice_) {
case 1: // Дата
oled.setScale(2);
oled.print(day);
oled.print(".");
oled.print(month);
oled.print(".");
oled.print(year);
oled.setCursor(0, 3);
oled.setScale(1);
if (hour < 10) {
oled.print("0");
}
oled.print(hour);
oled.print(":");
if (minute < 10) {
oled.print("0");
}
oled.print(minute);
oled.setCursor(0, 4);
oled.print("Установить");
if (btn_down.held()) {
oled.clear();
tmr_menu.start();
uint8_t choice__ = 1;
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
if (btn_down.held()) {
//oled.clear();
tmr_menu.start();
choice__ += 1;
if (choice__ > 3) {
choice__ = 1;
}
if (choice__ < 1) {
choice__ = 3;
}
}
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Дата");
oled.setCursor(0, 1);
oled.setScale(2);
if (day < 10) {
oled.print(" ");
}
oled.print(day);
oled.print(".");
if (month < 10) {
oled.print(" ");
}
oled.print(month);
oled.print(".");
if (year < 1000) {
oled.print(" ");
} else if (year < 100) {
oled.print(" ");
} else if (year < 10) {
oled.print(" ");
}
oled.print(year);
oled.print(" ");
oled.setCursor(0, 3);
switch (choice__) {
case 1: // Дата
if (day < 10) {
oled.print(" _ ");
} else {
oled.print("__ ");
}
if (btn_up.click()) {
tmr_menu.start();
day += 1;
if (day > 31 ) {
day = 1;
}
}
if (btn_down.click()) {
tmr_menu.start();
day -= 1;
if (day < 1 ) {
day = 31;
}
}
break;
case 2: // Месяц
if (month < 10) {
oled.print(" _ ");
} else {
oled.print(" __ ");
}
if (btn_up.click()) {
tmr_menu.start();
month += 1;
if (month > 12 ) {
month = 1;
}
}
if (btn_down.click()) {
tmr_menu.start();
month -= 1;
if (month < 1 ) {
month = 12;
}
}
break;
case 3: // Год
if (year > 1000) {
oled.print(" ____");
} else if (year > 100) {
oled.print(" ___");
} else if (year > 10) {
oled.print(" __");
} else {
oled.print(" _");
}
if (btn_up.click()) {
tmr_menu.start();
year += 1;
if (year > 9999 ) {
year = 1;
}
}
if (btn_down.click()) {
tmr_menu.start();
year -= 1;
if (year < 1 ) {
year = 2023;
}
}
break;
}
oled.update();
}
}
break;
case 2: // Время
oled.print(day);
oled.print(".");
oled.print(month);
oled.print(".");
oled.print(year);
oled.setCursor(0, 2);
oled.setScale(2);
if (hour < 10) {
oled.print("0");
}
oled.print(hour);
oled.print(":");
if (minute < 10) {
oled.print("0");
}
oled.print(minute);
oled.setScale(1);
oled.setCursor(0, 4);
oled.print("Установить");
if (btn_down.held()) {
oled.clear();
tmr_menu.start();
bool choice__ = true;
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
if (btn_down.held()) {
//oled.clear();
tmr_menu.start();
if (choice__ == true) {
choice__ = false;
} else {
choice__ = true;
}
}
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Время");
oled.setCursor(0, 1);
oled.setScale(2);
if (hour < 10) {
oled.print("0");
}
oled.print(hour);
oled.print(":");
if (minute < 10) {
oled.print("0");
}
oled.print(minute);
oled.setCursor(0, 3);
switch (choice__) {
case true: // Часы
oled.print("__ ");
if (btn_up.click()) {
tmr_menu.start();
hour += 1;
if (hour > 23) {
hour = 0;
}
}
if (btn_down.click()) {
tmr_menu.start();
hour -= 1;
if (hour < 0 ) {
hour = 23;
}
}
break;
case false: // Минуты
oled.print(" __");
if (btn_up.click()) {
tmr_menu.start();
minute += 1;
if (minute > 59 ) {
minute = 0;
}
}
if (btn_down.click()) {
tmr_menu.start();
minute -= 1;
if (minute < 0 ) {
minute = 59;
}
}
break;
}
oled.update();
}
}
break;
case 3: // Установить
oled.print(day);
oled.print(".");
oled.print(month);
oled.print(".");
oled.print(year);
oled.setCursor(0, 2);
if (hour < 10) {
oled.print("0");
}
oled.print(hour);
oled.print(":");
if (minute < 10) {
oled.print("0");
}
oled.print(minute);
oled.setScale(2);
oled.setCursor(0, 3);
oled.print("Установить");
if (btn_down.held()) {
//oled.clear();
tmr_menu.start();
// устанавливаем дату
clock.fillByYMD(year, month, day); // год, месяц, дата
clock.fillByHMS(hour, minute, 30); // часы, минуты, секунды
clock.setTime();
oled.setCursor(0, 3);
oled.print("Готово ");
oled.update();
delay(300);
}
break;
}
oled.update();
}
}
break;
case 3: // Батарея
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Настройки");
oled.setCursor(0, 1);
oled.print("Язык");
oled.setCursor(0, 2);
oled.print("Дата/время");
oled.setCursor(0, 3);
oled.setScale(2);
oled.print("Батарея");
if (btn_down.held()) {
oled.clear();
tmr_menu.start();
bool choice_ = true;
while (true) {
if ((tmr_menu.tick()) || (back == true)) {
oled.clear();
oled.update();
back = true;
break;
}
btn_up.tick();
btn_down.tick();
if (btn_up.held()) {
oled.clear();
tmr_menu.start();
break;
}
if ((btn_up.click()) || (btn_down.click())) {
tmr_menu.start();
oled.clear();
if (choice_ == true) {
choice_ = false;
} else {
choice_ = true;
}
}
switch (choice_){
case true:
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Батарея");
oled.setCursor(0, 1);
oled.setScale(2);
if (btn_down.held()) {
oled.print("Готово");
battery_setting = true;
tmr_menu.start();
} else {
oled.print("Иконка");
}
oled.setCursor(0, 3);
oled.setScale(1);
oled.print("Процентний");
//
//if (battery_setting == true) {
// oled.setCursor(0, 4);
// oled.print("true");
//}
break;
case false:
oled.setCursor(40, 0);
oled.setScale(1);
oled.print("Батарея");
oled.setCursor(0, 1);
oled.print("Иконка");
oled.setCursor(0, 2);
oled.setScale(2);
if (btn_down.held()) {
oled.setCursor(0, 2);
oled.print("Готово ");
battery_setting = false;
tmr_menu.start();
} else {
oled.print("Процентний");
}
//
//if (battery_setting == false) {
// oled.setScale(1);
// oled.setCursor(0, 3);
// oled.print("false");
//}
break;
}
oled.update();
}
}
break;
}
oled.update();
}
}
oled.update();
break;
}
}
}
void alarm_check() {
clock.getTime();
if ((clock.hour == alarm_hour) && (clock.minute == alarm_minute)) {
oled.setPower(true);
int alarm_done = 30;
while (true) {
btn_up.tick();
btn_down.tick();
if ((btn_up.click()) || (btn_down.click()) || (btn_up.held()) || (btn_down.held()) || (alarm_done == 0)) {
alarm_status = false;
oled.clear();
screen_status = true;
tmr_screen.start();
digitalWrite(vibrationPin, LOW);
break;
}
if (tmr_alarm.tick()) {
oled.drawBitmap(1, 1, alarm_7x8, 7, 8, BITMAP_NORMAL, BUF_ADD);
digitalWrite(vibrationPin, HIGH);
alarm_done -= 1;
} else {
oled.clear(1 ,1, 7, 8);
digitalWrite(vibrationPin, LOW);
}
oled.setScale(3);
oled.setCursor(16, 2);
if (clock.hour < 10) {
oled.print("0");
}
oled.print(clock.hour, DEC);
oled.print(":");
if (clock.minute < 10) {
oled.print("0");
}
oled.print(clock.minute, DEC);
oled.setCursor(32, 5);
oled.setScale(1);
oled.print(clock.dayOfMonth, DEC);
oled.print(".");
oled.print(clock.month, DEC);
oled.setCursor(68, 5);
switch (clock.dayOfWeek) { // День недели
case MON:
oled.print("ПНД"); // "MON"
break;
case TUE:
oled.print("ВТР"); // "TUE"
break;
case WED:
oled.print("СРД"); // "WED"
break;
case THU:
oled.print("ЧТВ"); // "THU"
break;
case FRI:
oled.print("ПТН"); // "FRI"
break;
case SAT:
oled.print("СБТ"); // "SAT"
break;
case SUN:
oled.print("ВСК"); // "SUN"
break;
}
charging = digitalRead(chargerPin);
charging_done = digitalRead(chargerPin_done);
//Serial.print("Зарядка идет - ");
//Serial.println(charging);
//Serial.print("Зарядка закончилась - ");
//Serial.println(charging_done);
if ((charging == true) && (charging_done == false)) {
if (tmr_charging.tick()) {
switch (charging_animation) {
case 0:
oled.clear(100, 1, 126, 11);
oled.drawBitmap(100, 1, bat25_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 1:
oled.drawBitmap(100, 1, bat50_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 2:
oled.drawBitmap(100, 1, bat75_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation += 1;
break;
case 3:
oled.drawBitmap(100, 1, bat100_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
//oled.update(100, 1, 126, 11);
charging_animation = 0;
break;
}
}
}
if ((charging == true) && (charging_done == true)) {
oled.drawBitmap(100, 1, bat_done_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
}
if ((charging == false) && (charging_done == false)) {
if (charging_animation > 0) {
charging_animation = 0;
}
oled.clear(100, 1, 126, 11);
if (battery > 75) {
oled.drawBitmap(100, 1, bat100_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery > 50) {
oled.drawBitmap(100, 1, bat75_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery > 25) {
oled.drawBitmap(100, 1, bat50_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
} else if (battery >= 0) {
oled.drawBitmap(100, 1, bat25_27x11, 27, 11, BITMAP_NORMAL, BUF_ADD);
}
}
oled.update();
}
}
}