ARM Linuxもだいぶいじっていくつかできそうなことが貯まってきました。ということで、LEDも点灯できていることですしディジタル時計を作ってみました。
ネットワーク同期式ですので正確です。
ハードウェア
利用したハードウェアは以下の通りです
- SAMA5D3 Xplained : Atmelの評価ボード
- 7セグメント4桁LED : シリアル接続可能なLEDモジュール
- AT Mega プロトシールド
LEDは先のエントリで説明したI2C接続になっています。
ソフトウェア
プログラムはpythonで書きました。便利なモジュールが揃っている上に、インタープリタで試行錯誤しながら組めるのであっという間でした。やっつけですので特に説明は無し。
import smbus
import time
i2c = smbus.SMBus(1) # open the /dev/i2c-1
address = 0x71 # address of 7seg display https://www.switch-science.com/catalog/1128/
while True:
now=time.strftime('%H%M%S') # get time by 6 digit
i2c.write_byte( address, 0x79 ) # set write cursor to digit 0
i2c.write_byte( address, 0x00 )
if now[0] == '0' : # need zero suppress?
i2c.write_byte( address, ord(' ') ) # display blank
else:
i2c.write_byte( address, ord(now[0]) ) # display digit
i2c.write_byte( address, ord(now[1]) ) #h
i2c.write_byte( address, ord(now[2]) ) #m
i2c.write_byte( address, ord(now[3]) ) #m
if now[5] in ['1','3','5','7','9']: # blink the colon
# turn colon on
i2c.write_byte( address, 0x77 )
i2c.write_byte( address, 0x10 )
else:
# turn colon off
i2c.write_byte( address, 0x77 )
i2c.write_byte( address, 0x00 )
# sleep 0.1sec
time.sleep(0.1)
できあがり写真。