-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.ino
75 lines (64 loc) · 2.01 KB
/
display.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
// utility function for digital clock display: prints leading 0
String twoDigits(int digits) {
if (digits < 10) {
String i = '0' + String(digits);
return i;
}
else {
return String(digits);
}
}
void displayweight(float weight){
display.clear();
display.setTextAlignment(TEXT_ALIGN_CENTER);
displayClock(); // display the selected clock to the OLED
display.setFont(ArialMT_Plain_24);
display.drawString(displayCenterX, displayCenterY + 4, String(weight,2)); // outpot the weight to the OLED
display.display();
}
void timeanddate() {
String timenow = String(hour()) + ":" + twoDigits(minute()) + ":" + twoDigits(second());
display.setFont(ArialMT_Plain_10);
display.drawString(displayCenterX, displayCenterY - 24, timenow + " " + currentDay + " " + currentMonth + " " + currentDate + " " + String( year())); // display time. day, month date and year
}
void timeandday() {
getCurrentTime();
display.setFont(ArialMT_Plain_10);
display.drawString(displayCenterX, displayCenterY - 24, currentDay + " " + currentTime ); // display day and time
}
void timeonly() {
getCurrentTime();
display.setFont(ArialMT_Plain_24);
display.drawString(displayCenterX, displayCenterY - 24, currentTime ); // display only the time
}
void displayClock() { // call the selected display for the clock
switch (whatclock)
{
case 1: { // Item 1
timeandday();
break;
}
case 2: { // Item 2
timeanddate();
break;
}
case 3: { // Item 3
timeonly();
break;
}
}
}
/*
* setup the OLED
*/
void setupdisplay() {
display.init();
display.setI2cAutoInit(true);
}
// get the time and the day
void getCurrentTime() {
currentTime = String(hour()) + ":" + twoDigits(minute());
currentMonth = monthstrings[month() - 1];
currentDate = String(day());
currentDay = daystrings[weekday() - 1];
}