/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body with MPU6050 + ILI9341 (Wokwi compatible)
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "mpu6050.h"
#include "ili9341.h"
/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;
SPI_HandleTypeDef hspi1;
/* USER CODE BEGIN PV */
MPU6050_Data mpu;
/* USER CODE END PV */
int main(void)
{
HAL_Init();
/* Initialize peripherals used by drivers */
MPU6050_Init(&hi2c1);
ILI9341_Init();
/* Fill screen with blue background */
ILI9341_Fill_Screen(0x001F);
while (1)
{
/* Read MPU6050 */
MPU6050_Read_All(&hi2c1, &mpu);
/* Convert acceleration to pixel position */
int16_t x = 160 + (mpu.Accel_X / 100);
uint16_t y = 120;
/* Clamp pixel position */
if (x >= 320) x = 319;
if (x < 0) x = 0;
/* Draw pixel */
ILI9341_Draw_Pixel(x, y, 0xF800);
HAL_Delay(100);
}
}
/* Error handler */
void Error_Handler(void)
{
while (1)
{
}
}