Last active
June 5, 2016 09:24
-
-
Save InuSasha/ca90ef13945ee340c40f697cae25b490 to your computer and use it in GitHub Desktop.
simple Python script to write time on adafruit 7 segement LED on LibreElec
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
# add to the config.txt of rpi | |
dtparam=i2c_arm=on |
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
#!/usr/bin/python | |
# import all needed libraries | |
import sys, signal, datetime, time | |
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib') | |
from Adafruit_LED_Backpack import SevenSegment | |
# function to break loop on SIGTERM | |
run = True | |
def on_exit(sig, func=None): | |
global run | |
run = False | |
signal.signal(signal.SIGTERM, on_exit) | |
# init display | |
display = SevenSegment.SevenSegment() | |
display.begin() | |
display.set_brightness(1) | |
# main loop | |
colon = True | |
while (run): | |
# write new time to display, invert colon | |
display.clear() | |
display.print_number_str(datetime.datetime.now().strftime('%H%M')) | |
colon = not colon | |
display.set_colon(colon) | |
display.write_display() | |
# wait till next second (bare in mind that set the display need time) | |
time.sleep(1 - (datetime.datetime.now().microsecond / 1000000.0)) | |
# clear display | |
display.clear() | |
display.write_display() |
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
[Unit] | |
Description=LED Date Update Daemon | |
After=local-fs.target | |
Wants=network-online.target | |
[Service] | |
ExecStart=/storage/.config/dated.py | |
ExecStop=/bin/kill -TERM $MAINPID | |
TimeoutStopSec=5 | |
Restart=always | |
RestartSec=2 | |
StartLimitInterval=0 | |
LimitNOFILE=16384 | |
[Install] | |
WantedBy=kodi.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment