#include <Wire.h>
#include <Adafruit_MPU9250.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>

#define TFT_CLK 21
#define TFT_DAT 20
#define TFT_CS   5
#define TFT_RST  4
#define TFT_DC   3

Adafruit_MPU9250 mpu;
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST, TFT_CLK, TFT_DAT);

const int screenWidth = 128;
const int screenHeight = 160;
const int crosshairSize = 10;

float accX, accY;

void setup() {
  Wire.begin();
  Serial.begin(115200);
  
  if (!mpu.begin()) {
    Serial.println("MPU9250 initialization failed!");
    while (1);
  }
  
  mpu.setAccelerometerRange(MPU9250_RANGE_2_G);
  
  tft.initR(INITR_BLACKTAB);
  tft.setRotation(3);
  tft.fillScreen(ST7735_BLACK);
  tft.setTextColor(ST7735_WHITE);
}

void loop() {
  mpu.readAcceleration(&accX, &accY, NULL);
  
  int crosshairX = screenWidth / 2 + accX * 10;
  int crosshairY = screenHeight / 2 + accY * 10;
  
  drawCrosshair(screenWidth / 2, screenHeight / 2, crosshairSize, ST7735_BLACK);
  drawCrosshair(crosshairX, crosshairY, crosshairSize, ST7735_WHITE);
  
  delay(100);
}

void drawCrosshair(int x, int y, int size, uint16_t