Skip to content

Instantly share code, notes, and snippets.

@heaversm
Created March 19, 2018 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heaversm/a71f954d3f9f000cb47067344ade09aa to your computer and use it in GitHub Desktop.
Save heaversm/a71f954d3f9f000cb47067344ade09aa to your computer and use it in GitHub Desktop.
Arduino Code to use the accelerometer of a LightBlue Bean to act as mouse x and y coordinates via HID
void setup() {
BeanHid.enable();
}
void loop() {
AccelerationReading accel = Bean.getAcceleration();
int16_t x = accel.xAxis;
int16_t y = accel.yAxis;
int16_t z = accel.zAxis;
if (abs(x) < 20) {
x = 0;
}
if (abs(y) < 20) {
y = 0;
}
int16_t mousex = map(x, -60, 60, -20, 20);
int16_t mousey = map(y, -60, 60, 20, -20);
BeanHid.moveMouse(mousex, mousey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment