Scroll pHAT HDでシンプルなデジタル時計を表示する

公式のサンプルとしては以下の2種類のデジタル時計のスクリプトが配布されています。

https://github.com/pimoroni/scroll-phat-hd/blob/master/examples/clock.py


https://github.com/pimoroni/scroll-phat-hd/blob/master/examples/portraitclock.py

これらはちょっと数字が縦に詰まっている印象を受けたので作ってみました。

num3x7.py

data = {

0x00000020: [[0x00,0x00]],

0x00000030: [[0x00,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0x00]],

0x00000031: [[0x00,0xff,0x00],
             [0xff,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00]],

0x00000032: [[0xff,0xff,0x00],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0x00,0xff,0x00],
             [0xff,0x00,0x00],
             [0xff,0x00,0x00],
             [0xff,0xff,0xff]],

0x00000033: [[0xff,0xff,0x00],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0xff,0xff,0x00],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0xff,0xff,0x00]],

0x00000034: [[0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0x00,0xff,0xff],
             [0xff,0x00,0xff],
             [0xff,0xff,0xff],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff]],

0x00000035: [[0xff,0xff,0xff],
             [0xff,0x00,0x00],
             [0xff,0x00,0x00],
             [0x00,0xff,0x00],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0xff,0xff,0x00]],

0x00000036: [[0x00,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0x00],
             [0xff,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0x00]],

0x00000037: [[0xff,0xff,0xff],
             [0x00,0x00,0xff],
             [0x00,0x00,0xff],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00],
             [0x00,0xff,0x00]],

0x00000038: [[0x00,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0x00]],

0x00000039: [[0x00,0xff,0x00],
             [0xff,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0xff],
             [0x00,0x00,0xff],
             [0xff,0x00,0xff],
             [0x00,0xff,0x00]],

0x0000003a: [[0x00],
             [0xff],
             [0x00],
             [0x00],
             [0x00],
             [0xff],
             [0x00]],

}
width = 3
height = 7

simpleclock.py

import time
import scrollphathd
import num3x7

scrollphathd.set_brightness(0.3)
while True:
    scrollphathd.clear()
    scrollphathd.write_string(time.strftime("%H:%M"), font=num3x7)
    if int(time.time()) % 2 == 0:
        scrollphathd.clear_rect(8, 0, 1, 6)
    scrollphathd.show()
    time.sleep(0.1)

Scroll pHAT HDを接続し、セットアップした後、num3x7.pyとsimpleclock.pyを同じディレクトリに置いて

$ python simpleclock.py

とすると以下のように表示されます。