Skip to content

Commit 85be9a2

Browse files
author
Kevin J Walters
committed
Changing micro:bit display representation to bytearray, converting range from 0..255 to 0..9
1 parent 012d82c commit 85be9a2

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

zhhclock/zc_bg_brightnesstest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def render(self, local_time, milliseconds, ticks_ms):
1111
for idx in range(min(len(self._zip), 255)):
1212
self._zip[idx] = (idx, 0, 0)
1313

14-
for idx in range(10):
15-
self._mdisplaylist[idx] = round(idx * 255 / 9.0)
14+
for idx in range(9 + 1):
15+
self._mdisplaylist[idx] = idx
1616

1717
return self.MICROBIT_CHANGED | self.HALO_CHANGED

zhhclock/zc_bg_digitalrain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def render(self, local_time, milliseconds, ticks_ms):
9999
brightness = (trail_bri * head_bri
100100
* max(0, (il_radius - distances[0])) / il_radius)
101101
if brightness > 0.0:
102-
self._mdisplaylist[m_idx] = max(round(brightness), self._mdisplaylist[m_idx])
102+
self._mdisplaylist[m_idx] = max(round(brightness / 255.0 * 9), self._mdisplaylist[m_idx])
103103

104104
self._last_run_tms = ticks_ms
105105
### TODO could count the changes

zhhclock/zc_bg_flag.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def flag_wales(self):
5858
// len(self._zip)]]
5959
### Off substitues for white on top left
6060
for idx in range(len(self._mdisplaylist)):
61-
self._mdisplaylist[idx] = 0 if idx in (0, 5) else 128
61+
self._mdisplaylist[idx] = 0 if idx in (0, 5) else 7 ### 7 out of 9
6262

6363
return self.HALO_CHANGED | self.MICROBIT_CHANGED
6464

@@ -93,8 +93,8 @@ def _wind_ripple(self, ripple_time, total, changes_):
9393
if idx != tophalf_idx:
9494
r, g, b = self._zip[tophalf_idx]
9595
self._zip[tophalf_idx] = (min(255, max(0, round(r * col_p1))),
96-
min(255, max(0, round(g * col_p1))),
97-
min(255, max(0, round(b * col_p1))))
96+
min(255, max(0, round(g * col_p1))),
97+
min(255, max(0, round(b * col_p1))))
9898

9999
if changes_ & self.MICROBIT_CHANGED:
100100
### Modulate micro:bit display using values calculated per column
@@ -103,7 +103,7 @@ def _wind_ripple(self, ripple_time, total, changes_):
103103
moving_x = 0 - led_x + shift_x
104104
col_p1 = self._wind_ripple_mod(moving_x) / 1.9 + 1.0
105105
for y_off in range(0, 25, 5):
106-
self._mdisplaylist[m_idx + y_off] = min(255,
106+
self._mdisplaylist[m_idx + y_off] = min(9,
107107
max(0,
108108
round(self._mdisplaylist[m_idx + y_off]
109109
* col_p1)))

zhhclock/zc_bg_larsonscanner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def render(self, local_time, milliseconds, ticks_ms):
2323
x3 = x1 - 0.150 * dir
2424

2525
z_bri = 30
26-
m_bri = 255
26+
m_bri = 9
2727
il_radius = 0.08
2828
for x in (x1, x2, x3):
2929
for p_idx in get_z_pixels_through_x(x):
@@ -37,8 +37,8 @@ def render(self, local_time, milliseconds, ticks_ms):
3737
distance = abs(M_LED_POS[m_idx][0] - x)
3838
brightness = (max(0, (il_radius - distance)) / il_radius)
3939
if brightness > 0.0:
40-
self._mdisplaylist[m_idx] = max(round(brightness * m_bri), self._mdisplaylist[m_idx])
41-
40+
self._mdisplaylist[m_idx] = max(round(brightness * m_bri),
41+
self._mdisplaylist[m_idx])
4242
z_bri /= 2
4343
m_bri /= 2
4444

zhhclock/zhhclock.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,9 @@ def writeto_mem(self, addr, memaddr, buf, *, addrsize=8):
118118
zip_px.fill(BLACK)
119119
zip_px.show()
120120

121-
display_image = [0] * (5 * 5)
122-
123-
microbit_bri_conv = 9.0 / 255.0
124-
ORD_ZERO = ord("0")
121+
display_image = bytearray(25) ### values are 0..9
125122
def show_display_image():
126-
### This converts integer (0..255) array into the MicroPython
127-
### text representation of an image
128-
img = ":".join(["".join([chr(ORD_ZERO
129-
+ round(x * microbit_bri_conv))
130-
for x in display_image[0+offset:5+offset]]) for offset in range(0, 25, 5)])
131-
display.show(Image(img))
123+
display.show(Image(5, 5, display_image))
132124

133125
show_display_image()
134126
gc.collect()

0 commit comments

Comments
 (0)