/**
* @author Rafael Martins de Sousa - RA: 220023201
* @brief Arquivo referente à "Desafio 10 - Acelerometro MPU6050
* exibido em display ILI9341"
*/
#include "SPI.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_MPU6050.h"
#include "Adafruit_Sensor.h"
// Display pins
#define DISPLAY_CS_PIN GPIO_NUM_26
#define DISPLAY_DC_PIN GPIO_NUM_27
Adafruit_MPU6050 mpu;
Adafruit_ILI9341 tft = Adafruit_ILI9341(DISPLAY_CS_PIN, DISPLAY_DC_PIN);
sensors_event_t accel;
sensors_event_t gyro;
void show_tft_header() {
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(4);
tft.setCursor(50, 0);
tft.print("UNI");
tft.setTextColor(ILI9341_RED);
tft.print("S");
tft.setTextColor(ILI9341_BLUE);
tft.println("AL");
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.setCursor(30, 35);
tft.println("Desafio 10");
tft.setTextSize(2);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Desafio 10");
Wire.begin();
// Initialize the display TFT
tft.begin();
// Prints the header
show_tft_header();
// Initialize the Accelerometer (MPU6050)
while (!mpu.begin()) {
Serial.println("MPU6050 initializing...");
delay(100);
}
Serial.println("MPU6050 ready!");
}
void loop() {
// print accel data
if (mpu.getAccelerometerSensor()->getEvent(&accel)) {
tft.setCursor(0, 80);
tft.println("Accel data (m/s^2):");
tft.print("X:");
tft.println(accel.acceleration.x);
tft.print("Y:");
tft.println(accel.acceleration.y);
tft.print("Z:");
tft.println(accel.acceleration.z);
}
// print gyro data
if (mpu.getGyroSensor()->getEvent(&gyro)) {
tft.setCursor(0, 160);
tft.println("Gyro data (RPS):");
tft.print("X:");
tft.println(gyro.gyro.x);
tft.print("Y:");
tft.println(gyro.gyro.y);
tft.print("Z:");
tft.println(gyro.gyro.z);
}
delay(2000);
// refresh display
tft.fillScreen(ILI9341_BLACK);
show_tft_header();
}