Hello again. I have this project of an anglemeter or inclinometer using MPU6050, Arduino Nano and a 4 digit 7 segment display. The project seems pretty easy, I already have the code and it works but I'm having some trouble with the display. The 7 segment display has to print the angle given by the MPU6050 which is printed on the Serial monitor and I've already achieved that, but it blinks really fast and it doesn't look very good. I hope that you can take a look at the code and tell me if there's anything I can do to make it work better. Thank you!
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment object
MPU6050 sensor;
// RAW VALUES FROM AXIS X, Y AND Z FROM THE MPU6050
int ax, ay, az;
void setup() {
Serial.begin(57600);
Wire.begin();
sensor.initialize();
if (sensor.testConnection()) Serial.println("Sensor iniciado correctamente");
else Serial.println("Error al iniciar el sensor");
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
}
void loop() {
sevseg.refreshDisplay();
// READING THE SPEEDS
sensor.getAcceleration(&ax, &ay, &az);
//FOR ANGLE CALCULATION:
float accel_ang_x=atan(ax/sqrt(pow(ay,2) + pow(az,2)))*(180.0/3.14);
float accel_ang_y=atan(ay/sqrt(pow(ax,2) + pow(az,2)))*(180.0/3.14);
//TO SHOW THE ANGLES SEPARATED BY A [tab]
Serial.print("Inclinacion en X: ");
Serial.print(accel_ang_x);
Serial.print("tInclinacion en Y:");
Serial.println(accel_ang_y,2);
sevseg.setNumber(accel_ang_y,2);
}
In the loop runs the program that measures the angle at which the MPU6050 is located. After that, the sevseg.setNumber(accel_ang_y,2); is the function to print the Y axis angle on the 7 segment display.