How do you save a maximum value on an LCD1602

I have an ADXL345 and a LCD1602 setup and it runs fairly smoothly, but i was wondering how to keep the maximum g-force value on the LCD screen so when I look at the screen after a period of time I know how much g-force is happening at the highest point.

Here is the code I have right now, I got it from the SparkFun website but it doesn’t keep the maximum value:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
 
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
 
 
float AccelMinX = 0;
float AccelMaxX = 0;
float AccelMinY = 0;
float AccelMaxY = 0;
float AccelMinZ = 0;
float AccelMaxZ = 0;
 
 
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("ADXL345 Accelerometer Calibration"); 
  Serial.println("");
  
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
}
 
void loop(void)
{
    Serial.println("Type key when ready..."); 
    while (!Serial.available()){}  // wait for a character
    
    /* Get a new sensor event */ 
    sensors_event_t accelEvent;  
    accel.getEvent(&accelEvent);
    
    if (accelEvent.acceleration.x < AccelMinX) AccelMinX = accelEvent.acceleration.x;
    if (accelEvent.acceleration.x > AccelMaxX) AccelMaxX = accelEvent.acceleration.x;
    
    if (accelEvent.acceleration.y < AccelMinY) AccelMinY = accelEvent.acceleration.y;
    if (accelEvent.acceleration.y > AccelMaxY) AccelMaxY = accelEvent.acceleration.y;
  
    if (accelEvent.acceleration.z < AccelMinZ) AccelMinZ = accelEvent.acceleration.z;
    if (accelEvent.acceleration.z > AccelMaxZ) AccelMaxZ = accelEvent.acceleration.z;
  
    Serial.print("Accel Minimums: "); Serial.print(AccelMinX); Serial.print("  ");Serial.print(AccelMinY); Serial.print("  "); Serial.print(AccelMinZ); Serial.println();
    Serial.print("Accel Maximums: "); Serial.print(AccelMaxX); Serial.print("  ");Serial.print(AccelMaxY); Serial.print("  "); Serial.print(AccelMaxZ); Serial.println();
 
    while (Serial.available())
    {
      Serial.read();  // clear the input buffer
    }
}

I have also attached the Schematic I am using if that provides any other help.

You haven't provided any code that involves your LCD.

Once you write that code you may find that your desired action is already being fulfilled.

Once something is displayed on the LCD it remains displayed until replaced with something else.

Don

floresta:
You haven’t provided any code that involves your LCD.

Once you write that code you may find that your desired action is already being fulfilled.

Once something is displayed on the LCD it remains displayed until replaced with something else.

Don

Oh thanks, i put the wrong code up. Here is the right one. Also it was from the Adeept website not Sparkfun.

#include <Wire.h>        
#include <LiquidCrystal.h>   

#define Register_ID 0   
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Register_Z0 0x36
#define Register_Z1 0x37
                    
#define Reg_OFSX 0x1E     
#define Reg_OFSY 0x1F
#define Reg_OFSZ 0x20
#define Reg_PWR_CTL 0x2D

LiquidCrystal lcd(4, 6, 10, 11, 12, 13);  
int ADXAddress = 0xA7>>1;  
int reading = 0;
int val = 0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
int Z1,Z0,Z_out;
double Xg,Yg,Zg;

void setup()
{
   lcd.begin(16, 2);       
   lcd.clear();             
   delay(100);
   Wire.begin();           
   setAccReg(0x31,0x0B);   
   setAccReg(0x2C,0x08);   
   setAccReg(0x2D,0x08);  
   setAccReg(0x2E,0x80);   
   setAccReg(0x1E,0x00);   
   setAccReg(0x1F,0x00);   
   setAccReg(0x20,0x05);   
   delay(100);
   Wire.beginTransmission(ADXAddress);
   Wire.write(Register_2D);
   Wire.write(8);
   Wire.endTransmission();
   delay(500);
}

void loop()
{
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_X0);
  Wire.write(Register_X1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    X0 = Wire.read();
    X1 = Wire.read();
    X1 = X1<<8;
    X_out = X0+X1;
  }
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_Y0);
  Wire.write(Register_Y1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    Y0 = Wire.read();
    Y1 = Wire.read();
    Y1 = Y1<<8;
    Y_out = Y0+Y1;
  }
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_Z0);
  Wire.write(Register_Z1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2);
  if(Wire.available()<=2)
  {
    Z0 = Wire.read();
    Z1 = Wire.read();
    Z1 = Z1<<8;
    Z_out = Z0+Z1;
  }

  Xg = X_out/256.00;   
  Yg = Y_out/256.00;
  Zg = Z_out/256.00;
  lcd.clear();         
  lcd.setCursor(0, 0); 
  lcd.print("Nate    X="); 
  lcd.print(Xg);
  lcd.setCursor(0, 1); 
  lcd.print("Y=");
  lcd.print(Yg);
  lcd.setCursor(8, 1); 
  lcd.print("Z=");
  lcd.print(Zg);
  delay(300);          
}

void setAccReg(int reg,byte value){
    setReg(ADXAddress,reg,value);    
}

void setReg(int device,int reg,byte value){
    Wire.beginTransmission(device);
    Wire.write(reg);
    Wire.write(value);
    Wire.endTransmission();
}

If I understand your question, which is that it's always showing the current value of Xg etc, I think you need to store the max values of Xg etc seen into other variables Xgmax etc, and display them.