CodeRigor

GUIDED LESSON / 1 OF 6

Define a motion event

Distinguish gravity, noisy samples and a deliberate counted burst.

What moves through this step
  1. 01Acceleration in g
  2. 02Magnitude²
  3. 03Threshold crossing
  4. 04Event count

Count a movement, not every sample

The CoreS3 includes an IMU and a screen, so this build needs no external sensor module. The finished counter runs offline and increments when a strong acceleration burst crosses its threshold after the device has returned to a lower-motion state.

An accelerometer at rest still measures gravity, approximately one g in magnitude. Counting every nonzero sample would immediately generate false events. We use the squared three-axis magnitude, with an entry threshold of 1.8 g and a rearm threshold below 1.2 g. This is an experiment-specific event policy, not a step, calorie or impact measurement.

Start with desktop C++

Unzip the project into a new directory and run:

Bash
c++ -std=c++17 -Wall -Wextra -Werror test_counter.cpp -o test_counter
./test_counter

These tests feed synthetic acceleration and timestamps into the policy. They verify edges, cooldown and rollover arithmetic, not physical sensor calibration or recognition quality.

Try it

Explain what should happen when acceleration stays high for a full second. Decide what observation should rearm the counter, then ask whether a second burst within 300 ms should be accepted.