Skip to content

Instantly share code, notes, and snippets.

@InuSasha
Last active June 5, 2016 09:24
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 InuSasha/ca90ef13945ee340c40f697cae25b490 to your computer and use it in GitHub Desktop.
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
# add to the config.txt of rpi
dtparam=i2c_arm=on
#!/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()
[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