AVR-Playground/main.c

63 lines
No EOL
1.5 KiB
C

/*
* This code utilizes the AVR libraries for I2C and UART communication.
* Make sure to connect the SDA and SCL pins of the ATmega328P to the
* corresponding pins of your I2C temperature sensor. Additionally, you might
* need pull-up resistors for the I2C lines.
*/
#define LED_PIN PB5 // Define the pin connected to the LED
#include <avr/io.h>
#include <avr/sleep.h>
#include <math.h>
#include <util/delay.h>
#include "MPU6050.h"
#include "i2c.h"
#include "uart.h"
void blink() {
// Set the LED pin as output
DDRB |= (1 << LED_PIN);
while (1) {
// Turn on the LED by setting the pin high
PORTB |= (1 << LED_PIN);
// Delay for 500 milliseconds
_delay_ms(500);
// Turn off the LED by setting the pin low
PORTB &= ~(1 << LED_PIN);
// Delay for 500 milliseconds
_delay_ms(500);
}
}
int main(void) {
int16_t accel_data[3]; // Array to store accelerometer data (X, Y, Z)
int32_t iteration = 0;
initUART();
UART_println("UART Initialized!");
DEBUG("DEBUG mode enabled!");
I2C_init(100000);
UART_println("I2C Initialized!");
MPU6050_Init();
UART_println("MPU6050 Initialized!");
while (1) {
UART_println("%d Hello, World!", iteration++);
// Read accelerometer data
UART_println("Reading MPU6050 accelerometer data...");
MPU6050_Read_Accel(accel_data);
UART_println("Accelerometer (mg): X=%d, Y=%d, Z=%d", accel_data[0], accel_data[1], accel_data[2]);
sleep_mode();
}
return 0;
}