Skip to content

Instantly share code, notes, and snippets.

@danya02
Last active July 25, 2020 17:05
Show Gist options
  • Select an option

  • Save danya02/82cb61617ad590c90f5e to your computer and use it in GitHub Desktop.

Select an option

Save danya02/82cb61617ad590c90f5e to your computer and use it in GitHub Desktop.

Revisions

  1. danya02 revised this gist Feb 9, 2016. No changes.
  2. danya02 created this gist Feb 9, 2016.
    36 changes: 36 additions & 0 deletions binary_clock.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/usr/bin/env python

    from sense_hat import SenseHat
    import time, datetime

    hat = SenseHat()

    year_color = (0, 255, 0)
    month_color = (0, 0, 255)
    day_color = (255, 0, 0)
    hour_color = (0, 255, 0)
    minute_color = (0, 0, 255)
    second_color = (255, 0, 0)
    hundredths_color = (127, 127, 0)
    off = (0, 0, 0)

    hat.clear()

    def display_binary(value, row, color):
    binary_str = "{0:8b}".format(value)
    for x in range(0, 8):
    if binary_str[x] == '1':
    hat.set_pixel(x, row, color)
    else:
    hat.set_pixel(x, row, off)

    while True:
    t = datetime.datetime.now()
    display_binary(t.year % 100, 0, year_color)
    display_binary(t.month, 1, month_color)
    display_binary(t.day, 2, day_color)
    display_binary(t.hour, 3, hour_color)
    display_binary(t.minute, 4, minute_color)
    display_binary(t.second, 5, second_color)
    display_binary(t.microsecond / 10000, 6, hundredths_color)
    time.sleep(0.0001)