Capture max analog values and displaying

Hi! I new here and could use a little help

I've put this code together from others.
The problem I'm trying to solve is having to max value continue showing and updating max
on the leds. The serial monitor works fine and stores max value.

Leds will show max value but as soon as it cools down it shows thous values.
I'm using uno, lm35, couple leds

(Not sure how to put code in box for forum)

Any help appreciated

code

//declare variables

 float tempC;
 int tempPin = 0;      // Where 0 is an analog input
 //int tempF
 int cel = 0, fahr = 0; // temperature variables
 int maxi = -100, mini = 100; // to start max/min temperature

 int blueled = 2;     //the pink led is connected to digital pin 2
 int yellowled = 6;   //the yellow led is connected to digital pin 6

 int A = 0;    // I use A to keep a value stored for the outside temperature in small numbers. At first it is zero
 int C = 0;    // C also helps defining what the position in the ones is. I will provide example

 void setup()
{
 Serial.begin(9600);   //opens serial port, sets data rate to 9600 bps

 pinMode(blueled, OUTPUT);
 pinMode(yellowled, OUTPUT);

}

 void loop()
{
 tempC = analogRead(tempPin);           //read the value from the sensor
 tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
 fahr = (tempC*1.8)+32;                //convert celcius to farenheit
 if (fahr > maxi) {maxi = fahr;}        // set max temperature
 
 Serial.println((byte)maxi);           //send the data to the computer

 A = fahr/10;
 C = fahr-(A*10);

 delay(1000);
 for (int i=0; i<(A); i ++)
{
 digitalWrite(blueled, HIGH);
 delay(500);
 digitalWrite(blueled, LOW);
 delay(300);
}
 delay(300);

 for (int n=0; n<( C ); n ++)
{
 digitalWrite(yellowled, HIGH);
 delay(600);
 digitalWrite(yellowled, LOW);
 delay(300);
}
 delay(2000);
}

Hello,

If i understand correctly (which is a big if) you need to change these lines:

  A = fahr/10;
  C = fahr-(A*10);

Here, you should use "maxi" instead of "fahr".

Also the above is how you should post code. Please edit your original post and fix that. Use the </> icon.

Paul

Hey Paul

That was it :slight_smile:

Works great now

Thanks Mike

No problem. Thanks for fixing your code tags. You should also try the "auto format" feature in the tools menu of the ide.