-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.ino
91 lines (85 loc) · 2.73 KB
/
clock.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
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C 헤더파일 호출
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD의 address 주소 및 크기 입력
void setup()
{
Serial.begin(115200); //통신을 위하여 사용
lcd.init(); // LCD 초기화
lcd.backlight(); // LCD 백라이트 함수
}
void loop()
{
String hour,h,m;
int hours, min;
int first;
int MinuteAngle = 0;
float hourAngle = 0;
float answer;
if (Serial.available() != 0)
{
hour = Serial.readString();
int leng = hour.length();
Serial.println(hour);
first = hour.indexOf(":");
h= hour.substring(0,first);
m= hour.substring(first+1,leng);
//Serial.println(leng + (String) " " + first + (String) " " + h +(String) " " + m);
hours = h.toInt();
min= m.toInt();
MinuteAngle = min * 6;
hourAngle = (hours*60 + min) * 0.5;
if (hourAngle >= 360){
hourAngle = hourAngle - 360;
}
//Serial.println((String) "Min" + MinuteAngle);
//Serial.println(hourAngle);
if (hourAngle > MinuteAngle){
if ((hourAngle - MinuteAngle)>180)
{
answer = 360 - (hourAngle - MinuteAngle);
Serial.println((String) "Angle : " + abs(answer));
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.print(hour);
lcd.setCursor(0,1);
lcd.print("Angle:");
lcd.print(abs(answer));
}
else
{
answer = hourAngle - MinuteAngle;
Serial.println((String) "Angle : " + abs(answer));
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.print(hour);
lcd.setCursor(0,1);
lcd.print("Angle:");
lcd.print(abs(answer));
}
}
else
{
if ((MinuteAngle - hourAngle)>180)
{
answer = 360 - (MinuteAngle - hourAngle);
Serial.println((String) "Angle : " + abs(answer));
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.print(hour);
lcd.setCursor(0,1);
lcd.print("Angle:");
lcd.print(abs(answer));
}
else
{
answer = MinuteAngle - hourAngle;
Serial.println((String) "Angle : " + abs(answer));
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.print(hour);
lcd.setCursor(0,1);
lcd.print("Angle:");
lcd.print(abs(answer));
}
}
}
}