By Leila Verhaegen and Emma Delescolle

@LeilaVerhaegen

@EmmaDelescolle

@Levit_SCS

We made a clock in Python

Who are we ?

  • Emma

  • cofounder of LevIT

  • Maintener of DRF-Schema-Adapter

  • Maintener of Ember-cli-crudities

  • Leila

  • cofounder of LevIT

  • young Python and EmberJs developer

  • who love playing with electronic and micro-bits

Why we made the small one

What did we use?

Quad-7-segment?

RTC?

Plan

Plan B

Little bit about code

pcf8523_light.py

 

RTC read/write

clock.py

 

the main clock management module

utils.py

 

binary to decimal converters

Little bit about code

pcf8523_light.py

    def read(self, reg_def, debug=False):
        if not self.i2c.try_lock():
            return [None]

        rv = bytearray(1)
        self.i2c.writeto(self.address, bytes([reg_def[0]]), stop=False)
        self.i2c.readfrom_into(self.address, rv)
        self.i2c.unlock()

        return [rv[0] & reg_def[1]]

    def write(self, reg_def, value, debug=False):
        buf = bytearray(2)
        buf[0] = reg_def[0]
        buf[1] = value

        if not self.i2c.try_lock():
            return False

        self.i2c.writeto(self.address, buf)
        self.i2c.unlock()

        return True

And now it works

Bigger! Better?

So here we are...

The challenge...

What exactly did I use?

Neopixels? What is that?

A lightbox? What?Why? How?

How did I build it?

How did I build it?

Plan

Same Program? What Program?

And what about code ?

...

if num == 0:
        pixels[pos*8 + 0] = color
        pixels[pos*8 + 1] = color
        pixels[pos*8 + 2] = color
        pixels[pos*8 + 4] = color
        pixels[pos*8 + 5] = color
        pixels[pos*8 + 6] = color
    elif num == 1:
        pixels[pos*8 + 2] = color
        pixels[pos*8 + 6] = color

...
def days_in_month(year, month):
    if month in (1, 3, 5, 7, 8, 10, 12):
        return 31
    elif month != 2:
        return 30
    elif is_leap(year):
        return 29
    return 28
def is_leap(year):
    if year % 4 != 0:
        return False
    if year % 100 != 0:
        return True
    return year % 400 == 0
if mode == 0:
        show_number(current.tm_hour // 10, pos=0)
        show_number(current.tm_hour % 10, pos=1)
        show_number(current.tm_min // 10, pos=2)
        show_number(current.tm_min % 10, pos=3)
        
        if btn_h.value is False:
            rtc.datetime = time.struct_time((current.tm_year, current.tm_mon, current.tm_mday,
                                             (current.tm_hour + 1) % 24, current.tm_min,
                                             0,0,9,-1))
            time.sleep(.1)
        elif btn_m.value is False:
            rtc.datetime = time.struct_time((current.tm_year, current.tm_mon, current.tm_mday,
                                             current.tm_hour, (current.tm_min + 1) % 60,
                                             0,0,9,-1))
            time.sleep(.1)

How long did it take?

And now it works !

Thank you !

How to find us?

@LeilaVerhaegen

@EmmaDelescolle

@levit_SCS

Twitter

 

Github

leila20

nanuxbe

website

https://levit.be

https://blog.levit.be

Bitbucket

levit_scs

Questions ?

Sources

  • https://ixquick-proxy.com/
  • https://thenextweb.com/dd/2017/01/20/six-reasons-your-logos-fail/
  • adafruit.com
  • 2018.pyconuk.org
  • https://www.dhgate.com/
  • https://www.core77.com/
  • https://www.uni-weimar.de
  • https://www.lightbulbs-direct.com

we made a clock in python - PyconUK 2018

By Emma

we made a clock in python - PyconUK 2018

pyconUK 2018 talk

  • 1,500