#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_MPU6050.h"
#include "Adafruit_Sensor.h"
#include "Wire.h"
Adafruit_MPU6050 mpu;
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int potPin = 34;
int potValue = 0;
bool ledStatus;
void setup() {
Serial.begin(115200);
tft.begin();
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello ESP32");
tft.setCursor(24, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can do SPI :-)");
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(1000);
}
void loop() {
Serial.println("OWEN");
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
tft.println(a.acceleration.x * 0.1);
tft.println("Accelerometer:");
tft.print(a.acceleration.x * 0.1);
tft.print(",");
tft.print(a.acceleration.y * 0.1);
tft.print(",");
tft.println(a.acceleration.z * 0.1);
tft.println("");
tft.println("Gyroscope:");
tft.print(g.gyro.x);
tft.print(",");
tft.print(g.gyro.y);
tft.print(",");
tft.println(g.gyro.z);
tft.println("==============================");
delay(1000);
potValue = analogRead(potPin);
tft.println(potValue);
delay(1000);
}