Simple test
Ensure your device works with this simple test.
examples/displayio_flipclock_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4"""
5An example that shows how to initialize and use the FlipClock displayio object.
6
7This example is the most basic usage of FlipClock and is not intended to count
8time or any other specific units or values.
9"""
10
11import time
12
13import adafruit_imageload
14import board
15from displayio import Group
16
17from adafruit_displayio_flipclock.flip_clock import FlipClock
18
19# == Configuration Variables ==
20
21# seconds per animation frame
22ANIMATION_DELAY = 0.01
23
24# number of frames in the animation
25ANIMATION_FRAME_COUNT = 10
26
27# color indexes that will be made transparent in the palette
28TRANSPARENT_INDEXES = range(11)
29
30# Brightness modifier for top half during animation
31BRIGHTER_LEVEL = 0.99
32
33# Brightness modifier for bottom half in the shadow during animation
34DARKER_LEVEL = 0.5
35
36# Brightness modifier to use by default for static sprites
37MEDIUM_LEVEL = 0.9
38
39# == END configuration variables ==
40
41# access built-in display
42display = board.DISPLAY
43
44# load the static sprite sheet
45static_spritesheet, static_palette = adafruit_imageload.load("static_sheet.bmp")
46static_palette.make_transparent(0)
47
48# load the animation sprite sheets
49top_animation_spritesheet, top_animation_palette = adafruit_imageload.load(
50 "grey_top_animation_sheet.bmp"
51)
52bottom_animation_spritesheet, bottom_animation_palette = adafruit_imageload.load(
53 "grey_bottom_animation_sheet.bmp"
54)
55
56# set the transparent color indexes in respective palettes
57for i in TRANSPARENT_INDEXES:
58 top_animation_palette.make_transparent(i)
59 bottom_animation_palette.make_transparent(i)
60
61# calculate sprite size by dividing total sheet
62SPRITE_WIDTH = static_spritesheet.width // 3
63SPRITE_HEIGHT = (static_spritesheet.height // 4) // 2
64
65# initialize FlipClock widget object
66clock = FlipClock(
67 static_spritesheet,
68 static_palette,
69 top_animation_spritesheet,
70 top_animation_palette,
71 bottom_animation_spritesheet,
72 bottom_animation_palette,
73 SPRITE_WIDTH,
74 SPRITE_HEIGHT,
75 anim_delay=ANIMATION_DELAY,
76 brighter_level=BRIGHTER_LEVEL,
77 darker_level=DARKER_LEVEL,
78 medium_level=MEDIUM_LEVEL,
79)
80
81# position it in the center of the display
82clock.anchor_point = (0.5, 0.5)
83clock.anchored_position = (display.width // 2, display.height // 2)
84
85# group to hold our flip clock
86main_group = Group()
87
88# append the clock to the group
89main_group.append(clock)
90
91# show the group on the display
92board.DISPLAY.root_group = main_group
93
94# set a value to start with in the first pair
95clock.first_pair = "13"
96
97while True:
98 # increment first pair number
99 cur_val = clock.first_pair
100 next_val = int(cur_val) + 1
101
102 # if it's time to reset
103 if next_val > 20:
104 # reset value back to 0
105 next_val = 0
106
107 # set the first pair value on the FlipClock
108 clock.first_pair = str(next_val)
109
110 # increment second pair value
111 cur_val = clock.second_pair
112 next_val = int(cur_val) + 1
113
114 # if it's time to reset
115 if next_val > 99:
116 # reset value back to 0
117 next_val = 0
118
119 # set the second pair value on the FlipClock
120 clock.second_pair = str(next_val)
121
122 time.sleep(0.5)