Need help on a "CountDown" - Clock

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gadrecs
 
Posts: 7
Joined: Fri Aug 27, 2021 6:02 am

Need help on a "CountDown" - Clock

Post by gadrecs »

Hi all,

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
Last edited by Franklin97355 on Fri Aug 27, 2021 11:37 am, edited 1 time in total.
Reason: Added code tag.

User avatar
gadrecs
 
Posts: 7
Joined: Fri Aug 27, 2021 6:02 am

Re: Need help on a "CountDown" - Clock

Post by gadrecs »

Addon:

i played around some more and changed the "forever"-Loop to this.

while True:
# 0.1 secs to make it faster for testing
time.sleep(.1)
count -= 1
text1 = str(count)
gatter.remove(text_area1)
text_area1 = label.Label(font1, text=text1, background_color=black, background_tight=True)
gatter.append(text_area1)
text_area1.x = 14
text_area1.y = 15

Problem now is, that the Digits are "blinking" or better flickering on every iteration, which i wanted to prevent as i need a calm an "quiet" display.

User avatar
robertcarell
 
Posts: 6
Joined: Tue Aug 10, 2021 11:34 pm

Re: Need help on a "CountDown" - Clock

Post by robertcarell »

I am trying to understand this question but I didn't get that which microcontroller you are using for this project?

User avatar
gadrecs
 
Posts: 7
Joined: Fri Aug 27, 2021 6:02 am

Re: Need help on a "CountDown" - Clock

Post by gadrecs »

Hi & thanks for the reply.

i´m using a M4 Matrix Portal with an 64x32 RGB HUB75 Display for this.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Need help on a "CountDown" - Clock

Post by adafruit_support_mike »

[moved to the CircuitPython forum]

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”