Created
July 22, 2016 11:40
-
-
Save ufian/c3fd700160451aebecc2b67d8eca7c58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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