/********* 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: "Gyroscope Initialization"
	- Source Code NOT compiled for: Arduino Nano ESP32
	- Source Code created on: 2024-06-05 22:24:38

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* read gyroscope at maximum rate and show on serial. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <Wire.h>
#include <MPU6050.h>  //https://github.com/electroniccats/mpu6050

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t sensor_MPU6050_Interrupt_PIN_D2 = 2;

/***** DEFINITION OF I2C PINS *****/
const uint8_t sensor_MPU6050_I2C_PIN_SDA_A4 = A4;
const uint8_t sensor_MPU6050_I2C_PIN_SCL_A5 = A5;
const uint8_t sensor_MPU6050_I2C_SLAVE_ADDRESS = 0x68;  // MPU6050 I2C address

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
MPU6050 accelgyro(sensor_MPU6050_I2C_SLAVE_ADDRESS);  // Initialize MPU6050 object with I2C address

void setup(void)
{
    // Initialize I2C communication
    Wire.begin(sensor_MPU6050_I2C_PIN_SDA_A4, sensor_MPU6050_I2C_PIN_SCL_A5);
    
    // Initialize serial communication
    Serial.begin(38400);
    Serial.println("Initializing I2C devices...");
    
    // Initialize MPU6050
    accelgyro.initialize();
    
    // Test connection
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    
    // Set interrupt pin as input
    pinMode(sensor_MPU6050_Interrupt_PIN_D2, INPUT);
}

void loop(void)
{
    // Variables to hold gyroscope data
    int16_t gx, gy, gz;
    
    // Read gyroscope data
    accelgyro.getRotation(&gx, &gy, &gz);

    // Print gyroscope data to serial monitor
    Serial.print("Gyroscope X: "); Serial.print(gx);
    Serial.print(" | Gyroscope Y: "); Serial.print(gy);
    Serial.print(" | Gyroscope Z: "); Serial.println(gz);
}
