Skip to content

Instantly share code, notes, and snippets.

@interstar
Last active July 12, 2021 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interstar/9b34c8d0d12a324ca2c56d9915172af8 to your computer and use it in GitHub Desktop.
Save interstar/9b34c8d0d12a324ca2c56d9915172af8 to your computer and use it in GitHub Desktop.
Grab MicroBit Accelerometer to Serial
# See https://www.youtube.com/watch?v=DcgRHOqSFm8
from microbit import *
uart.init(baudrate=115200)
while True:
display.clear()
x,y,z=accelerometer.get_values()
display.set_pixel(2,2,4)
if x < -300 : display.set_pixel(0,2,9)
if x > 300 : display.set_pixel(4,2,9)
if y < -300 : display.set_pixel(2,0,9)
if y > 300 : display.set_pixel(2,4,9)
uart.write("%s,%s,%s,%s,%s\n\r"%(x,y,z,button_a.is_pressed(),button_b.is_pressed()))
sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment