adjustable digital spirit level

Sorry cant do it as it gives a error message ( Post crosses the limit of 9000 characters) hence have attached the .ino file

Hi
I am working on a project where I am trying to make an "adjustable digital spirit level". I have a mpu9250 with pro mini and OLED display. I am getting the X and Y axis display on the OLED.
Aim:

  • Place the appliance at the desired angle on the platform and press the push button.
  • The angle values in X and Y axis get stored.
  • While replacing the platform, recheck the angle by placing the appliance on the platform.
  • If the angle changes more than 10 , there is a buzzer sound and LED glows. Preferably 2 LED one for X axis and One for Y axis offset.
    Need Guidance:
  1. Steps to be taken during coding.
  2. How do I go about defining a variable which stores the selected value of X and Y
  3. Do I need to execute the angle calculation code again after the push button is pressed? Or one time code is sufficient.
    I have seen a couple of code for thermostat where a specific temperature value was entered with a keypad, but have not come across a code where an certain value from the sensor is taken as a reference value .
    I am a beginner and learning the intricacies of coding, at present I rely on using codes from the internet and adapting them to my needs.
    Please guide as how I should go about this project and if there and are any examples you know of.

Outline of the project

  1. Define: push button, Led, MPU , buzzer.
  2. Include : Libraries- U8glib.h
  • Wire.h
  1. Code for MPU to calculate X,Y Z axis value.
  2. Now what---?
    In my code the next step is printing to the serial port and Display. I want to select the values of X,Y axis displayed on the screen with the push of the button. These values will become the reference values and any deviation of more than 10 in either axis will sound the buzzer and light up the relevant LED.
    Now where do I put the - selection code,
  • If ,else condition

sketch_adjustable_spirit_levela.ino (8.91 KB)