Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Last active March 11, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/fedcc233cfd9b26eda1a80a740d570e5 to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/fedcc233cfd9b26eda1a80a740d570e5 to your computer and use it in GitHub Desktop.
Displays the full date and time on a waveshare e-paper display (2.13in V2)
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd2in13_V2
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
logging.info("time demo")
epd = epd2in13_V2.EPD()
logging.info("init and Clear")
epd.init(epd.FULL_UPDATE)
epd.Clear(0xFF)
fontSizeLarge = 100
fontSizeSmall = 25
font = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), fontSizeLarge)
fontSmall = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), fontSizeSmall)
logging.info("show time...")
time_image = Image.new('1', (epd.height, epd.width), 255)
time_draw = ImageDraw.Draw(time_image)
epd.init(epd.FULL_UPDATE)
epd.displayPartBaseImage(epd.getbuffer(time_image))
epd.init(epd.PART_UPDATE)
print(epd.height, epd.width) # 250 122
dateFormat = '%A, %m/%d/%Y'
timeFormat = '%H:%M' #'%H:%M:%S'
x = 0 #(epd.height - fontSize * 2) / 2
paddingBottom = 0
y = 0
print(x,y)
backgroundX = x + len(timeFormat) * fontSizeLarge
while (True):
time_draw.rectangle((x, y, backgroundX if backgroundX < epd.height else epd.height , y + fontSizeLarge + fontSizeSmall), fill = 255)
time_draw.text((x, y), time.strftime(dateFormat), font = fontSmall, fill = 0)
time_draw.text((x, y + fontSizeSmall), time.strftime(timeFormat), font = font, fill = 0)
epd.displayPartial(epd.getbuffer(time_image))
time.sleep(5)
# epd.Clear(0xFF)
logging.info("Clear...")
epd.init(epd.FULL_UPDATE)
epd.Clear(0xFF)
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd2in13_V2.epdconfig.module_exit()
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment