参考:
- Programming the BBC micro:bit: Getting Started with MicroPython, p.96
- micro:bitではじめるプログラミング ―親子で学べるプログラミングとエレクトロニクス (Make:PROJECTS), p.45-48
使用しているチップは MMA8653FC。
from microbit import * from random import randint janken = (Image("00000:" #stone "09990:" "09990:" "09990:" "00000:"), Image("99999:" #paper "90009:" "90009:" "90009:" "99999:"), Image("00990:" #scissors "00909:" "99099:" "00909:" "00990:")) while True: if accelerometer.current_gesture() == "shake": display.show(janken[randint(0, 2)])
shake のほかに up, down, left, right, face up, face down, freefall, 3g, 6g, 8g の各ジェスチャーが取得できる。