Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Accelerometer Data**
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2024-12-21 15:44:26
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* El objetivo del proyecto es crear un sistema */
- /* Arduino que utilice bibliotecas específicas para */
- /* la gestión de sensores, asegurando un */
- /* procesamiento de datos eficiente y una interacción */
- /* fluida del usuario a través de funciones bien */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_ADXL343.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Instantiate the Adafruit_ADXL343 object with a unique ID
- Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);
- void setup(void)
- {
- Serial.begin(9600);
- while (!Serial); // Wait for Serial Monitor to open
- Serial.println("Accelerometer Test");
- Serial.println("");
- /* Initialise the sensor */
- if (!accel.begin())
- {
- /* There was a problem detecting the ADXL343 ... check your connections */
- Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
- while (1);
- }
- /* Set the range to whatever is appropriate for your project */
- accel.setRange(ADXL343_RANGE_16_G);
- /* Display some basic information on this sensor */
- displaySensorDetails();
- displayDataRate();
- displayRange();
- Serial.println("");
- }
- void loop(void)
- {
- /* Get a new sensor event */
- sensors_event_t event;
- accel.getEvent(&event);
- /* Display the results (acceleration is measured in m/s^2) */
- Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
- Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
- Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" "); Serial.println("m/s^2 ");
- delay(500);
- }
- /* Function to display sensor details */
- void displaySensorDetails(void)
- {
- sensor_t sensor;
- accel.getSensor(&sensor);
- Serial.println("------------------------------------");
- Serial.print("Sensor: "); Serial.println(sensor.name);
- Serial.print("Driver Ver: "); Serial.println(sensor.version);
- Serial.print("Unique ID: "); Serial.println(sensor.sensor_id);
- Serial.print("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
- Serial.print("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
- Serial.print("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2");
- Serial.println("------------------------------------");
- Serial.println("");
- delay(500);
- }
- /* Function to display data rate */
- void displayDataRate(void)
- {
- Serial.print("Data Rate: ");
- switch (accel.getDataRate())
- {
- case ADXL343_DATARATE_3200_HZ: Serial.print("3200 "); break;
- case ADXL343_DATARATE_1600_HZ: Serial.print("1600 "); break;
- case ADXL343_DATARATE_800_HZ: Serial.print("800 "); break;
- case ADXL343_DATARATE_400_HZ: Serial.print("400 "); break;
- case ADXL343_DATARATE_200_HZ: Serial.print("200 "); break;
- case ADXL343_DATARATE_100_HZ: Serial.print("100 "); break;
- case ADXL343_DATARATE_50_HZ: Serial.print("50 "); break;
- case ADXL343_DATARATE_25_HZ: Serial.print("25 "); break;
- case ADXL343_DATARATE_12_5_HZ: Serial.print("12.5 "); break;
- case ADXL343_DATARATE_6_25HZ: Serial.print("6.25 "); break;
- case ADXL343_DATARATE_3_13_HZ: Serial.print("3.13 "); break;
- case ADXL343_DATARATE_1_56_HZ: Serial.print("1.56 "); break;
- case ADXL343_DATARATE_0_78_HZ: Serial.print("0.78 "); break;
- case ADXL343_DATARATE_0_39_HZ: Serial.print("0.39 "); break;
- case ADXL343_DATARATE_0_20_HZ: Serial.print("0.20 "); break;
- case ADXL343_DATARATE_0_10_HZ: Serial.print("0.10 "); break;
- default: Serial.print("???? "); break;
- }
- Serial.println(" Hz");
- }
- /* Function to display range */
- void displayRange(void)
- {
- Serial.print("Range: +/- ");
- switch (accel.getRange())
- {
- case ADXL343_RANGE_16_G: Serial.print("16 "); break;
- case ADXL343_RANGE_8_G: Serial.print("8 "); break;
- case ADXL343_RANGE_4_G: Serial.print("4 "); break;
- case ADXL343_RANGE_2_G: Serial.print("2 "); break;
- default: Serial.print("?? "); break;
- }
- Serial.println(" g");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement