Recording Peak Value

Hi All,

I’ve got a load cell attached to my Mega2560 and I’m trying to record the peak value and display it on the LCD. Here’s my code that does not work:

#include <LiquidCrystal.h>

int previousValue = 0;
int currentValue = 0;
int peakValue = 0;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.print(“Peak Value”);
}

void loop(){
currentValue = analogRead(A7);
if (currentValue > previousValue)
{
peakValue = currentValue;
}

Serial.println(currentValue);
lcd.setCursor(0,1);
lcd.print(peakValue);
}

Any thoughts on what I’m doing wrong?

Thanks

When does previousValue get updated? I would think the previousValue is the old peak value, so you can just substitute previousValue with peakValue, and it should work.

That worked!

Thanks a lot!