Created
February 25, 2026 13:41
-
-
Save evildmp/0ca1c2fe97ede55e9595222ceaa5b4b6 to your computer and use it in GitHub Desktop.
Dotty microbit toy
This file contains hidden or 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
| # Imports go at the top | |
| from microbit import * | |
| # starting x and y positions | |
| x = 2 | |
| y = 2 | |
| # set a bright pixel at x and y | |
| display.set_pixel(x, y, 9) | |
| # how much does the microbit need to tilt? | |
| threshold = 100 | |
| while True: | |
| # turn off the active pixel | |
| display.set_pixel(x, y, 0) | |
| # get the x and y tilt values | |
| x_tilt = accelerometer.get_x() | |
| y_tilt = accelerometer.get_y() | |
| # depending on the tilt, change x and y | |
| if x > 0 and x_tilt < -threshold: | |
| x = x - 1 | |
| if x < 4 and x_tilt > threshold: | |
| x = x + 1 | |
| if y > 0 and y_tilt < -threshold: | |
| y = y - 1 | |
| if y < 4 and y_tilt > threshold: | |
| y = y + 1 | |
| # set a new bright pixel at x and y | |
| display.set_pixel(x, y, 9) | |
| # wait for 200 milliseconds | |
| sleep(200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment