This time we'll capture movement gestures, as recognised by the micro:bit's built-in accelerometer sensor.
from microbit import *
while True:
# obtain the current gesture
g = accelerometer.current_gesture()
# is the micro:bit face up or face down?
if g == 'face up':
display.show(Image.HAPPY)
else:
display.show(Image.SAD)
Once again we indent the main code inside a While True: endless loop so the program can continuously test for gesture changes.
After you've downloaded and run this program on the micro:bit modify the code to discover other recognised gestures, such as: 'up', 'down', 'left', 'right', 'freefall' and 'shake'.
Return to the BBC micro:bit MicroPython Coding Tutorials page.
No comments:
Post a Comment