Skip to content

Instantly share code, notes, and snippets.

@thinkier
Last active February 6, 2026 06:33
Show Gist options
  • Select an option

  • Save thinkier/1be94a168187e1447c1a809e8c2001d5 to your computer and use it in GitHub Desktop.

Select an option

Save thinkier/1be94a168187e1447c1a809e8c2001d5 to your computer and use it in GitHub Desktop.
#include "Arduino_BMI270_BMM150.h"
void setup() {
Serial.begin(9600);
if (!IMU.begin()) {
while (1);
}
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
}
void loop() {
float x, y, z;
float xy, angle;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
xy = sqrt(pow(x, 2) + pow(y, 2));
angle = atan2f(xy, z) * 180. / PI;
Serial.println(angle);
// The board definitions for ABX00069 (BLE Sense Rev 2) seem to have swapped green and blue
if (angle < 1) {
digitalWrite(LEDR, HIGH);
digitalWrite(LEDB, LOW);
digitalWrite(LEDG, HIGH);
} else if (angle < 3) {
digitalWrite(LEDR, LOW);
digitalWrite(LEDB, LOW);
digitalWrite(LEDG, HIGH);
} else {
digitalWrite(LEDR, LOW);
digitalWrite(LEDB, HIGH);
digitalWrite(LEDG, HIGH);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment