The code presented on this page can be downloaded or found in the Arduino examples menu under Examples → SpinWearables → Tilt_Sensor → Fancy
.
Ensure all of the SpinWheel hardware is on.
Read all sensor data.
Scale the x and y measurement to a -255..255 range.
Turn all large LEDs white.
If the tilt is in a given direction, turn on the corresponding LED purple.
Do the same for the Y orientation
Use the setSmallLEDsPointer
to turn on only the small LEDs which are at the top. This requires some tricky inverse trigonometry, where we use the arctan function to turn the ay
and ax
measurements into an angle. Then we rescale that angle to fit the 0..255 range used by setSmallLEDsPointer
.
Turn on the LEDs as commanded above.