A snippet of the code that updates the frames, and below that, an output of the print statements.
Code: Select all
...
x = 0
y = 0
direction_x = True
direction_y = True
prev_time = None
while True:
prev_x = x
prev_y = y
# Move bars
x += (1 if direction_x else -1)
y += (1 if direction_y else -1)
# Bounce back, if required
if x == 128:
direction_x = False
x = 126
elif x == -1:
direction_x = True
x = 1
if y == 64:
direction_y = False
y = 63
elif y == -1:
direction_y = True
y = 1
# Draw new lines
for i in range(64):
display.set_pixel(prev_x, i, False)
display.set_pixel(x, i, True)
for i in range(128):
display.set_pixel(i, prev_y, False)
display.set_pixel(i, y, True)
if prev_time is not None:
print(pyb.millis() - prev_time)
# Make sure the corners are active
display.set_pixel(0, 0, True)
display.set_pixel(127, 0, True)
display.set_pixel(0, 63, True)
display.set_pixel(127, 63, True)
prev_time = pyb.millis()
# Write display buffer
display.display()
...
Code: Select all
...
104
82
29
37
42
47
53
59
64
70
76
81
86
92
97
103
94
28
35
41
47
52
57
63
69
74
79
86
91
97
102
107
27
34
40
46
52
57
62
68
73
79
84
90
96
101
107
37
33
39
45
51
56
61
67
72
78
84
89
95
100
106
49
32
39
44
49
55
60
66
72
77
83
89
94
99
105
62
31
37
43
48
54
60
66
71
77
82
88
93
98
105
74
30
37
42
48
53
59
64
70
...