/*
*/
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <SPI.h>
Adafruit_MPU6050 mpu;
U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
int bubble_left_right, bubble_acc_brake;
// X axis on Acceleromter
double right_max = 0, left_max = 0; //left and right force max values in g
// Y axis on Accelerometer
double acc_max = 0, bake_max = 0; //acceleration and brake force max values in g
double bubble_right_max = 94, bubble_left_max = 94, bubble_bake_max = 31, bubble_acc_max = 31;
void setup(void) {
Serial1.begin(115200);
u8g2.begin();
u8g2.clearBuffer();
u8g2.sendBuffer();
while (!mpu.begin()) {
Serial1.println("MPU6050 not connected!");
delay(1000);
}
Serial1.println("MPU6050 ready!");
}
sensors_event_t event;
void loop() {
mpu.getAccelerometerSensor()->getEvent(&event);
// Max right force
bubble_left_right = map(event.acceleration.x, 10, -10, 123, 65);
bubble_acc_brake = map(event.acceleration.y, 10, -10, 2, 60);
if (event.acceleration.x > right_max) { right_max = event.acceleration.x; }
if (event.acceleration.x < left_max) { left_max = event.acceleration.x; }
if (event.acceleration.y > bake_max) { bake_max = event.acceleration.y; }
if (event.acceleration.y < acc_max) { acc_max = event.acceleration.y; }
if (bubble_left_right > bubble_right_max & bubble_left_right < 124) { bubble_right_max = bubble_left_right; }
if (bubble_left_right < bubble_left_max & bubble_left_right > 64) { bubble_left_max = bubble_left_right; }
if (bubble_acc_brake > bubble_bake_max & bubble_acc_brake < 61) { bubble_bake_max = bubble_acc_brake; }
if (bubble_acc_brake < bubble_acc_max & bubble_acc_brake > 1) { bubble_acc_max = bubble_acc_brake; }
u8g2.clearBuffer();
u8g2.drawFilledEllipse(bubble_left_right, bubble_acc_brake, 3.5, 3.5, U8G2_DRAW_ALL); // dot which flies around
//outer circle
u8g2.drawCircle(94, 31, 30, U8G2_DRAW_ALL); // outer unfilled circle
u8g2.drawCircle(94, 31, 29.5, U8G2_DRAW_ALL); // makes outer circle thicker
// bubble
u8g2.drawFilledEllipse(94, 31, 1.5, 1.5, U8G2_DRAW_ALL); // inner dot filled
// max lines
u8g2.drawLine(94, bubble_acc_max, bubble_left_max, 31);
u8g2.drawLine(94, bubble_bake_max, bubble_left_max, 31);
u8g2.drawLine(94, bubble_acc_max, bubble_right_max, 31);
u8g2.drawLine(94, bubble_bake_max, bubble_right_max, 31);
// vertical lines
//u8g2.drawLine(94, 2, 94, 60); // single vertical line
u8g2.drawLine(91, 19, 97, 19);
u8g2.drawLine(91, 9, 97, 9);
u8g2.drawLine(91, 43, 97, 43);
u8g2.drawLine(91, 53, 97, 53);
// horizontal lines
//u8g2.drawLine(65, 31, 123, 31); // single horizontal line
u8g2.drawLine(72, 28, 72, 34);
u8g2.drawLine(82, 28, 82, 34);
u8g2.drawLine(105, 28, 105, 34);
u8g2.drawLine(115, 28, 115, 34);
// max values on display
u8g2.setFont(/*u8g2_font_04b_03b_tr*/u8g2_font_spleen5x8_mu);
u8g2.setCursor(0, 10);
u8g2.print("ACC: ");
u8g2.print(bubble_acc_max);
u8g2.setCursor(0, 25);
u8g2.print("DCC: ");
u8g2.print(bubble_bake_max);
u8g2.setCursor(0, 40);
u8g2.print("L: ");
u8g2.print(bubble_left_max);
u8g2.setCursor(0, 55);
u8g2.print("R: ");
u8g2.print(bubble_right_max);
u8g2.sendBuffer();
}