forked from VolosR/ClockM5Stick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClockM5Stick.ino
126 lines (99 loc) · 2.84 KB
/
ClockM5Stick.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <M5StickC.h>
#include "AXP192.h"
#include "7seg20.h"
#include "ani.h"
#define grey 0x65DB
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
int bright[4]={8,9,10,12};
void setup() {
pinMode(39,INPUT_PULLUP);
pinMode(37,INPUT_PULLUP);
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setSwapBytes(true);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK);
//M5.Lcd.setTextColor(grey,TFT_BLACK);
//M5.Lcd.fillRect(112,12,40,40,TFT_RED);
// M5.Lcd.pushImage(112,12,40,40,ani[frame]);
M5.Axp.EnableCoulombcounter();
M5.Axp.ScreenBreath(bright[0]);
RTC_TimeTypeDef TimeStruct;
TimeStruct.Hours = 10;
TimeStruct.Minutes = 16;
TimeStruct.Seconds = 00;
// M5.Rtc.SetTime(&TimeStruct); set your time here uncomment
RTC_DateTypeDef DateStruct;
DateStruct.WeekDay = 2;
DateStruct.Month = 11;
DateStruct.Date = 24;
DateStruct.Year = 2020;
// M5.Rtc.SetData(&DateStruct); .....set your date here, uncomment
}
int H=0;
int M=0;
String ho="";
String mi="";
String se="";
String days[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int c=0;
int pres=0;
bool spavanje=0;
bool inv=0;
int frame=0;
void loop() {
spavanje=0;
if(digitalRead(37)==0)
{
if(pres==0)
{
pres=1;
c++;
if(c>3)
c=0;
M5.Axp.ScreenBreath(bright[c]);
M5.Lcd.fillRect(146,55,8,30,TFT_BLACK);
}
}else{pres=0;}
M5.Rtc.GetTime(&RTC_TimeStruct);
M5.Rtc.GetData(&RTC_DateStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.setTextFont(0);
M5.Lcd.drawString(String( M5.Axp.GetBatVoltage())+" V ",114,3);
M5.Lcd.setFreeFont(&DSEG7_Classic_Bold_30);
if(H!=int(RTC_TimeStruct.Hours) || M!=int(RTC_TimeStruct.Minutes)){
ho=String(RTC_TimeStruct.Hours);
if(ho.length()<2)
ho="0"+ho;
mi=String(RTC_TimeStruct.Minutes);
if(mi.length()<2)
mi="0"+mi;
M5.Lcd.drawString(ho+":"+mi,2,46);
H=int(RTC_TimeStruct.Hours);
M=int(RTC_TimeStruct.Minutes);
}
// M5.Lcd.printf("Week: %d\n",RTC_DateStruct.WeekDay);
se=String(RTC_TimeStruct.Seconds);
if(se.length()<2)
se="0"+se;
M5.Lcd.drawString(se,112,57,4);
M5.Lcd.drawString(days[RTC_DateStruct.WeekDay-1]+" ",4,0,2);
M5.Lcd.setTextColor(grey,TFT_BLACK);
M5.Lcd.drawString(String(RTC_DateStruct.Date)+"/"+String(RTC_DateStruct.Month),4,20,4);
M5.Lcd.drawString(String(RTC_DateStruct.Year),70,28,2);
M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK);
for(int i=0;i<c+1;i++)
M5.Lcd.fillRect(146,73-(i*5),8,3,grey);
if(digitalRead(39)==LOW){
while(digitalRead(39)==LOW);
M5.Lcd.invertDisplay(inv);
inv=!inv;
}
M5.Lcd.pushImage(112,12,40,40,ani[frame]);
frame++;
if(frame==132)
frame=0;
delay(12);
}