Skip to content

Instantly share code, notes, and snippets.

@kvasdopil
Created October 25, 2023 10:14
Show Gist options
  • Save kvasdopil/46f648c0607b123bbffd3d691cf42c39 to your computer and use it in GitHub Desktop.
Save kvasdopil/46f648c0607b123bbffd3d691cf42c39 to your computer and use it in GitHub Desktop.
Report accelerometer value of minew beacon
digitalPulse(LED1, true, 200);
I2C1.setup({sda: D12, scl: D11});
const acc = require("LIS3DH").connectI2C(I2C1);
function ypl(a) {
const x = a.x;
const y = a.y;
const z = a.z;
// Calculate the length
const length = Math.sqrt(x * x + y * y + z * z);
// Calculate the pitch angle (in degrees)
const pitchRad = Math.atan2(-z, y);
const pitchDeg = (180 / Math.PI) * pitchRad;
// Calculate the yaw angle (in degrees)
const yawRad = Math.atan2(y, x);
const yawDeg = (180 / Math.PI) * yawRad;
// Calculate the roll angle (in degrees)
const rollRad = Math.atan2(y, z);
const rollDeg = (180 / Math.PI) * rollRad;
return [
length,
pitchDeg,
yawDeg,
rollDeg,
];
}
setInterval(() => {
const a = acc.read();
console.log(ypl(a.x, a.y, a.z));
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment