i´m having an issue trying to build a count-down-clock:
i define some static text and lines using ".append".
then i also create the countdown-value and have it displayed.
in a while-Loop i change the value and update it again with .append
but: after some 70-80 iterations , the program stops with a memory error .....
what am i doing wrong ? how do i just have the 3 digits updated and not "rewritten/attached" ??
Kind regards and thanks in advance !
heres the code:
Code: Select all
## Archery-Clock v2.0
##
import time
import gc
import board
import displayio
from adafruit_matrixportal.matrix import Matrix
from adafruit_display_shapes.circle import Circle
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
from adafruit_display_shapes.rect import Rect
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.roundrect import RoundRect
from adafruit_display_shapes.triangle import Triangle
from adafruit_display_shapes.line import Line
from adafruit_display_shapes.polygon import Polygon
matrix = Matrix()
display = matrix.display
display.auto_refresh = True
# Make the display context
gatter = displayio.Group()
display.show(gatter)
#counter = displayio.Group()
#display.show(counter)
white=0x999999
black=0x000000
red=0x880000
green=0x008800
blue=0x000088
yellow=0x888800
orange=0x884400
font1 = bitmap_font.load_font("/fonts/spacemono-bold-20.bdf")
font2 = bitmap_font.load_font("/fonts/advancedpixel.bdf")
rect = Rect(0, 0, 64, 8, fill=green)
gatter.append(rect)
line1 = Line(14, 8, 14, 31, white)
gatter.append(line1)
line2 = Line(0, 8, 66, 8, white)
gatter.append(line2)
count = 240
text1 = str(count)
text_area1 = label.Label(font1, text=text1, background_color=black, background_tight=True)
text_area1.x = 14
text_area1.y = 15
gatter.append(text_area1)
# static text #1
text2 = "CD"
text_area2 = label.Label(font2, text=text2, color=0x04eb9f)
text_area2.x = 1
text_area2.y = 13
gatter.append(text_area2)
# static text #2
text3 = "P2"
text_area3 = label.Label(font2, text=text3, color=0x5E0110)
text_area3.x = 1
text_area3.y = 24
gatter.append(text_area3)
while True:
# 0.1 secs to make it faster for testing
time.sleep(0.1)
count -= 1
text1 = str(count)
text_area1 = label.Label(font1, text=text1, background_color=0x000000, background_tight=True)
gatter.append(text_area1)
text_area1.x = 14
text_area1.y = 15
pass