The code presented on this page can be downloaded or found in the Arduino examples menu under Examples → SpinWearables → Tilt_Sensor → Simple
.
#include "SpinWearables.h"
using namespace SpinWearables;
void setup() {
Ensure all of the SpinWheel hardware is on.
.begin();
SpinWheel}
void loop() {
Read all sensor data.
.readIMU(); SpinWheel
Scale the x and y measurement to a -255..255 range.
int x = SpinWheel.ax*255;
int y = SpinWheel.ay*255;
Turn off all LEDs.
.clearAllLEDs(); SpinWheel
If the tilt is in a given direction, turn on the corresponding LED.
if (x>10) {
.setLargeLED(5, x, x, x);
SpinWheel}
else if (x<-10) {
.setLargeLED(7, -x, -x, -x);
SpinWheel}
Do the same for the Y orientation
if (y>10) {
.setLargeLED(4, x, x, x);
SpinWheel}
else if (y<-10) {
.setLargeLED(6, -x, -x, -x);
SpinWheel}
Turn on the LEDs as commanded above.
.drawFrame();
SpinWheel}