Created
January 11, 2022 17:27
-
-
Save daj/6a9f964a422e1cb67f93c2d5e29013a4 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() { | |
var bgColor = "#9933FF"; | |
var fontColor = "#7300E6"; | |
g.setBgColor(bgColor); | |
g.setColor(bgColor); | |
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.setColor(fontColor); | |
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("Vector", 14); | |
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 >= 10) { | |
g.drawString("GO TO BED!", 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("Sammy", g.getWidth()/2, 70, false); | |
g.setColor(0xB319FF); | |
//g.drawRect(1, 1, 174, 174); | |
//g.drawRect(2, 2, 173, 173); | |
//g.drawRect(3, 3, 172, 172); | |
//g.drawRect(4, 4, 171, 171); | |
} | |
// 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