1. Reference
  2. Metadata

<accelerometer>

An invisible motion sensor that publishes live acceleration readings as $id variables.

Metadata

This tag has more than one name. Every spelling is the same tag, so write whichever feels natural. Pick one and every example on this page uses it.

This tag needs a motion sensor, so try it on your phone.

accelerometer.ham
<column style="items-center gap-8">
    <accelerometer id="motion"
                   precision="1"/>
    <text style="muted">Shake your phone</text>
    <text @text="#motion.value + ' m/s²'"
          style="font-3xl font-bold"></text>
    <text @text="'Last 10 s: ' + #motion.10s.total"
          style="muted text-sm"></text>
</column>
The snippet drawn by Hype Apps on a phone, in light mode The snippet drawn by Hype Apps on a phone, in dark mode
This snippet as Hype Apps draws it on a phone. It follows this page's light or dark theme.

Attributes

NameWhat it doesDefault
precision Decimals every published value is rounded to.
number
3

Readings

NameWhat it does
avg The average magnitude over the window before it (#id.1s.avg).
max The largest magnitude in the window before it (#id.5s.max).
total The time integral of the magnitude over the window before it (#id.10s.total), sample-rate independent.
value The instantaneous magnitude, gravity removed, in m/s²; with a window before it (#id.1s.value), the window's average.
x.avg The x axis, as avg is.
x.max The x axis, as max is.
x.total The x axis, as total is.
x.value The x axis, absolute, as value is; a window may follow the axis (#id.x.1s.value).
y.avg The y axis, as avg is.
y.max The y axis, as max is.
y.total The y axis, as total is.
y.value The y axis, as value is.
z.avg The z axis, as avg is.
z.max The z axis, as max is.
z.total The z axis, as total is.
z.value The z axis, as value is.

Any tag also takes gestures: @on.tap, @on.longpress, @on.doubletap and @on.swipeleft (and right, up and down). @click runs on a tap too.

This page is also Markdown, and all of HAM is in llms.txt.