[Project Help] Hold steady game with ArduinoUNO,MPU6050 & MAX7219 8x8 Led Matrix

Good day! Me and a friend have been working on this project for a few weeks now as an opportunity to learn a bit about the Arduino which we will apparently will use more often in our apprenticeship.

The general idea was pretty simple and I got it from an escape room puzzle I did before.
In the puzzle you had to carry a box from room A to Room B and hold it very steady, if it leaned too much to either side it would lock down and you had to place it on the table in room A again till it resets and try again.

In those weeks of trying to realize it we stumbled on a lot of post that did something similar and with each post and project we found we came a bit closer to making it work but I think we finally ran out of projects similars to ours.

Here is the code we have at this moment:

#include <Wire.h>
#include <MPU6050.h>
#include <LedControl.h>

int DIN = 12;
int CLK = 11;
int CS = 10;
unsigned long delaytime=100;

LedControl lc=LedControl(DIN,CLK,CS,0);

MPU6050 mpu;

// Timers
unsigned long timer = 0;
float timeStep = 0.01;

// Pitch, Roll and Yaw values
float pitch = 0;
float roll = 0;
float yaw = 0;

void setup() {
  // put your setup code here, to run once:

  // Initialize MPU6050
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
  // Calibrate gyroscope. The calibration must be at rest.
  // If you don't want calibrate, comment this line.

  // Set threshold sensivty. Default 3.
  // If you don't want use threshold, comment this line or set 0.

  lc.shutdown(0,false);       //The MAX72XX is in power-saving mode on startup
  lc.setIntensity(0,15);      // Set the brightness to maximum value
  lc.clearDisplay(0);         // and clear the display


void loop() {
  // put your main code here, to run repeatedly:
 timer = millis();

  // Read normalized values
  Vector norm = mpu.readNormalizeGyro();

  // Calculate Pitch, Roll and Yaw
  pitch = pitch + norm.YAxis * timeStep;
  roll = roll + norm.XAxis * timeStep;
  yaw = yaw + norm.ZAxis * timeStep;

  // Output raw
  Serial.print(" Pitch = ");
  Serial.print(" Roll = ");
  Serial.print(" Yaw = ");

  // Wait to full timeStep period
  delay((timeStep*1000) - (millis() - timer));

if (pitch > 1) {

  else if (pitch < 1) {


// if (GyroY < -500){
//  lc.setLed(0,0,0,true);
// }
//else {
//  lc.setLed(0,0,0,false);


Like you can see its pretty hacked together at some points. We got it so it gives out a nice readable pitch and yaw value in the Seriel Monitor. But we couldn’t find a better way to move the Point (Supposed to be 4 light LEDs on the matrix) one to the Side or Up when the pitch or yaw reach a certain value. Aside from the problem that this already takes 31% of the space we have for the code. Then we came across this: https://www.hackster.io/metascenes/visual-accelerometer-dee4bb

In particular this part

  // Convert the values into values that can be represented on the matrix
  x = map(x, -300, 300, 0, 8);
  y = map(y, -300, 300, 0, 8);
  z = map(z, -300, 300, 0, 8);

  //we send the x y z values as a string to the serial port
  Serial.print("X: ");
  Serial.print("   Y: ");
  Serial.print("   Z: ");

  // assign the grain to this location
  g->x = x;
  g->y = y;
  lc.setLed(0, g->x, g->y, true);

where as far as we can figure out he uses a modified value that his gyroscope spits out and lets the Matrix use it directly to change the position of the “dot”.

With this another problem surfaced as we tried to combine our script and the new idea we found.
In his example he is using and ADXL345 instead of our MDU6050 and they seem to work a bit differently. So we got out the Datasheets for both of them and tried to just change all the adresses to the right Value so it would also work with our MDU6050.

There are 2 solutions that would help us complete our project:

1.: A ways to use our MDU5060 in the ADXL345 Script
2.: A different way to move the “Dot” in our original Script.

We are very aware that this was a bit to complicated for our first project with Arduino and that we are in a bit in over our head but it would mean a lot to us if you could help us finishing this problem.

Thanks for reading.

Ps.: Im pretty confident in my english but there still might be some spelling errors, its not my first language but I understand it well enough.

I'm not sure whether I understand your problem(s) :frowning:

Do you get stable values when then box stands still on the desk?
Do you get the same (zero) angles when you move the box, then put it back on the desk?

Why do you delay the display?
See BlinkWithoutDelay for better (non-blocking) timing.

Which patterns do you try to show? Try something simpler first.