Created
March 19, 2018 03:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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