Due to high demand and inclement weather, expect some shipping delays at this time, orders may not ship for 4-5 business days.

Refresh a display

Hello,

I am using a Clue board with the latest circuit python and libraries (as of last week).

I am trying to display an analog clock face. However, I can not get the hands to move. I have tried auto refresh false with a manual refresh and I have tried with the refresh at default. I can move the circle by changing x and y. I can change text, but so far I can not figure out how to refresh a line.

Below is a simplified copy of my code. The line simply does not move.

Yes, I know everyone else uses group or splash where I used canvas. Canvas is just easier for me. Also, I can guess where the group usage came from, but why use splash? What is splash?

Code: Select all | TOGGLE FULL SIZE
import board
import displayio
import terminalio
import math
import time

RED = 0x880000
GREEN = 0x008800
BLUE = 0x000088
YELLOW = 0x884400
CYAN = 0x0088BB
MAGENTA = 0x9900BB
WHITE = 0x888888
display = board.DISPLAY
canvas = displayio.Group()
display.show(canvas)

palette = displayio.Palette(3)
palette[0] = 0x125690
palette[2] = 0xFF00FF

cx = 110
cy = 110
edge = 10
R = 100

circle = Circle(cx, cy, R, fill=0, outline=GREEN, stroke=3)
canvas.append(circle)

# x and y start of the line
startX = cx
startY = cy

# here is an angle just to get the line started
angle = 45

# x and y end of the line
endX = startX + round(math.cos(angle) * R)
endY = startY - round(math.sin(angle) * R)
line = Line(startX, startY, round(endX), round(endY), color=0x00FF00)
canvas.append(line)

time.sleep(1)

while True:
# new angle just to see the refresh work
newAngle = 185
endX = startX + round(math.cos(newAngle) * R)
endY = startY - round(math.sin(newAngle) * R)
line.x0 = 110
line.y0 = 110
line.x1 = round(endX)
line.y1 = round(endY)
# print statements to show that the line start and end points have changed.
print("line x and y", line.x, line.y)
print("line x0 and y0: ", line.x0, line.y0)
print("line x1 and y1: ", line.x1, line.y1)

display.refresh()
time.sleep(1)
markh9

Posts: 6
Joined: Fri Feb 28, 2014 2:10 pm

Re: Refresh a display

Something like this?

Code: Select all | TOGGLE FULL SIZE
import board
import displayio
import terminalio
import math
import time

RED = 0x880000
GREEN = 0x008800
BLUE = 0x000088
YELLOW = 0x884400
CYAN = 0x0088BB
MAGENTA = 0x9900BB
WHITE = 0x888888
display = board.DISPLAY
display.auto_refresh = False
canvas = displayio.Group()
display.show(canvas)

palette = displayio.Palette(3)
palette[0] = 0x125690
palette[2] = 0xFF00FF

edge = 10
cx = display.width // 2
cy = display.height // 2
sec_radius = min(display.width, display.height) // 2 - edge
sec_colour = WHITE
min_colour = YELLOW
hour_colour = MAGENTA

endX = cx + round(math.sin(angle) * radius)
endY = cy - round(math.cos(angle) * radius)
return Line(cx, cy, endX, endY, color=color)

circle = Circle(cx, cy, sec_radius, fill=0, outline=GREEN, stroke=3)
canvas.append(circle)
sec_idx = len(canvas)
min_idx = len(canvas)
hour_idx = len(canvas)

start_ns = time.monotonic_ns()
while True:
seconds = (time.monotonic_ns() - start_ns) / 1e9
sec_hand_angle = math.radians(math.fmod(seconds, 60.0) * (360 / 60))
min_hand_angle = math.radians(math.fmod(seconds, 3600.0) * (360 / 3600))
hour_hand_angle = math.radians(math.fmod(seconds, 43200.0) * ( 360 / 43200))