File: analog_watch.py

package info (click to toggle)
firmware-microbit-micropython 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 25,448 kB
  • sloc: ansic: 83,496; cpp: 27,664; python: 2,475; asm: 274; makefile: 245; javascript: 41; sh: 25
file content (35 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from microbit import *

hands = Image.ALL_CLOCKS

#A centre dot of brightness 2.
ticker_image = Image("2\n").crop(-2,-2,5,5)

#Adjust these to taste
MINUTE_BRIGHT = 0.1111
HOUR_BRIGHT = 0.55555

#Generate hands for 5 minute intervals
def fiveticks():
    fivemins = 0
    hours = 0
    while True:
        yield  hands[fivemins]*MINUTE_BRIGHT + hands[hours]*HOUR_BRIGHT
        fivemins = (fivemins+1)%12
        hours = (hours + (fivemins == 0))%12

#Generate hands with ticker superimposed for 1 minute intervals.      
def ticks():
    on = True
    for face in fiveticks():
        for i in range(5):
            if on:
                yield face + ticker_image
            else:
                yield face - ticker_image
            on = not on

#Run a clock speeded up 60 times, so we can watch the animation.
for tick in ticks():
    display.show(tick)
    sleep(1000)