Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from microbit import *
last_x = 2
last_y = 2
def get_index(raw_value, last_index):
index = int(round((raw_value / 100) + 2, 0))
return min(max(index, max(last_index - 1, 0)), min(last_index + 1, 4))
while True:
for num in range(10):
x = accelerometer.get_x()
y = accelerometer.get_y()
z = accelerometer.get_z()
last_x = x = get_index(x, last_x)
last_y = y = get_index(y, last_y)
if not num:
for i in range(5):
for j in range(5):
value = display.get_pixel(i, j)
if value > 0:
display.set_pixel(i, j, value - 1)
#display.clear()
value = display.get_pixel(x, y)
value = 9#min(value + 1, 9)
display.set_pixel(x, y, value)
sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment