Created
January 14, 2022 02:54
-
-
Save daj/9162d180cc9701f8e674f98dc4e45c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load fonts | |
require("Font7x11Numeric7Seg").add(Graphics); | |
// position on screen | |
const X = 160, Y = 140; | |
function draw() { | |
//g.setBgColor(0x33FF77); | |
//setColor("#0000FF") | |
g.setBgColor("#00FF00"); | |
g.setColor("#00FF00"); | |
g.fillRect(0, 26, 175, 175); | |
// work out how to display the current time | |
var d = new Date(); | |
var h = d.getHours(); | |
var m = d.getMinutes(); | |
var am = true; | |
if (h > 12) { | |
am = false; | |
h = h - 12; | |
} else if (h == 0) { | |
h = 12; | |
} | |
var time = (" "+h).substr(-2) + ":" + ("0"+m).substr(-2); | |
// Reset the state of the graphics library | |
g.reset(); | |
// draw the current time (4x size 7 segment) | |
g.setFont("7x11Numeric7Seg",4); | |
g.setFontAlign(1,1); // align right bottom | |
g.drawString(time, X, Y, false); | |
// draw the seconds (2x size 7 segment) | |
//g.setFont("7x11Numeric7Seg",2); | |
//g.drawString(("0"+d.getSeconds()).substr(-2), X+30, Y, true /*clear background*/); | |
// draw the date, in a normal font | |
g.setFont("6x8"); | |
g.setFontAlign(0,1); // align center bottom | |
// pad the date - this clears the background if the date were to change length | |
var dateStr = " "+require("locale").date(d)+" "; | |
g.drawString(dateStr, g.getWidth()/2, Y+15, false); | |
// AM/PM | |
var ampm = "PM"; | |
if (am) { | |
ampm = "AM"; | |
} | |
g.drawString(ampm, 164, 140, false); | |
// Custom | |
g.setFontAlign(0,0).setFont("Vector",18); | |
if (am) { | |
g.drawString("Good morning", g.getWidth()/2, 40, false); | |
} else if ((h >= 9) && (m >= 30)) { | |
g.drawString("Good night", g.getWidth()/2, 40, false); | |
} else if (h >= 6) { | |
g.drawString("Good evening", g.getWidth()/2, 40, false); | |
} else { | |
g.drawString("Good afternoon", g.getWidth()/2, 40, false); | |
} | |
// Name | |
g.setFontAlign(0,0).setFont("Vector",32); | |
g.drawString("Oliver", g.getWidth()/2, 70, false); | |
} | |
// Clear the screen once, at startup | |
g.clear(); | |
// draw immediately at first | |
draw(); | |
var secondInterval = setInterval(draw, 1000); | |
// Stop updates when LCD is off, restart when on | |
Bangle.on('lcdPower',on=>{ | |
if (secondInterval) clearInterval(secondInterval); | |
secondInterval = undefined; | |
if (on) { | |
secondInterval = setInterval(draw, 1000); | |
draw(); // draw immediately | |
} | |
}); | |
// Show launcher when middle button pressed | |
Bangle.setUI("clock"); | |
// Load widgets | |
Bangle.loadWidgets(); | |
Bangle.drawWidgets(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment