Professional Documents
Culture Documents
Ai Code
Ai Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
// Global Variables
float x, y, z;
float min_x, max_x, min_y, max_y, min_z, max_z;
float threshold = 2.0;
void setup() {
Serial.begin(9600);
// Initialize Accelerometer
if(!accel.begin()) {
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
// Set Range
accel.setRange(ADXL345_RANGE_2_G);
void loop() {
// Get acceleration measurements from the accelerometer
sensors_event_t event;
accel.getEvent(&event);
// Check if acceleration measurements are within threshold
if (abs(event.acceleration.x - min_x) > threshold ||
abs(event.acceleration.y - min_y) > threshold ||
abs(event.acceleration.z - min_z) > threshold) {