<aside> đź’ˇ Here are a few accelerometer functions that might useful for the Algorithmic Agent project

</aside>

Detecting a “snap”

The following code contains a function that sends the text “snap” over serial when it detects a strong jerk in the X axis direction of the accelerometer. The threshold parameter determines the minimum acceleration required to trigger a “snap”.

https://makecode.microbit.org/_7DkCtXi4CTbL

Specifically, the function is looking out for ascending crossings of the threshold for the X acceleration.

Screenshot 2022-02-12 10.52.00 AM.png

Detecting 2D tilt

The function returns the 2D tilt of the micro:bit. Imagine that the micro:bit is a joystick (rest position = micro:bit flat on the table) and this functions gives you the angle that the joystick is tilted towards.

https://makecode.microbit.org/_UM2EDkFUuC3e

The angle of the tilt is given in radians from -pi to pi (essentially a full circle).

micro_bit 2D tilt.png