5 max in DC voltmeter

Hi
This is a DC voltmeter with displaying max value of DC voltage ( max DC hold ).

const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
//double maxValue = 0;
#include <LiquidCrystal.h>

LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

float val = 0;// define the variable as value=0

void setup()

{
lcd.begin(16, 2);
 }

void loop()
{
  val = analogRead(PA7);
  U1 = (val * 3.3) / 4.096;

  if (val > maxValue)
  {
    maxValue = val;
  }

  lcd.setCursor(0, 0);
  lcd.print(U1, 0); //Print the number of val on the LCD

  lcd.setCursor(5, 0);
  lcd.print(maxValue, 0);

  delay(200); //Wait for 200ms

}

Rotating potentiometer 5 times back and forth I want to display all 5 different max values,

This is what I did, but it is obviously that all max are the same. How to make them different ?

const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
//++++++++++++++++++++++
float maxValue1 = 0;
float maxValue2 = 0;
float maxValue3 = 0;
float maxValue4 = 0;
float maxValue5 = 0;
//+++++++++++++++++++++++
#include <LiquidCrystal.h>

LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

float val = 0;// define the variable as value=0

void setup()

{

  lcd.begin(16, 2);
  pinMode(PA7, INPUT);// input

}

void loop()
{
  val = analogRead(PA7);
  U1 = (val * 3.3) / 4.096;

  if (val > maxValue)
  {
    maxValue = val;
  }
//+++++++++++++++++++
if (val > maxValue1)
  {
    maxValue1 = val;
  }
  if (val > maxValue2)
  {
    maxValue2 = val;
  }
  if (val > maxValue3)
  {
    maxValue3 = val;
  }
  if (val > maxValue4)
  {
    maxValue4 = val;
  }
  if (val > maxValue5)
  {
    maxValue5 = val;
  }

//++++++++++++++++++
/*
  lcd.setCursor(0, 0);
  lcd.print(U1, 0); //Print the number of val on the LCD

  lcd.setCursor(5, 0);
  lcd.print(maxValue, 0);
  */
  //+++++++++++++++++++++++++
  lcd.setCursor(0, 0);
  lcd.print(maxValue1, 0);
  lcd.setCursor(5, 0);
  lcd.print(maxValue2, 0);
  lcd.setCursor(9, 0);
  lcd.print(maxValue3, 0);
  lcd.setCursor(0, 1);
  lcd.print(maxValue4, 0);
  lcd.setCursor(5, 1);
  lcd.print(maxValue5, 0);
  //+++++++++++++++++++++++++

  delay(200); //Wait for 200ms

}

How about an array?

Good idea
Don't know how to implement it here.

First, think about what conditions you will use to index the array.

like this ?


/////////////
int  myArray[]= {maxValue1,maxValue2,maxValue3,maxValue4,maxValue5};
////////////


x != y;


if (val > maxValue1)
  {
    maxValue1 = val;
  }

  
  if (val != maxValue2)
  {
    maxValue2 = val;
  }
 
  if (val != maxValue3)
  {
    maxValue3 = val;
  }

  
  if (val != maxValue4)
  {
    maxValue4 = val;
  }

 
  if (val != maxValue5)
  {
    maxValue5 = val;
  }

1 different and 4 the same

const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
//++++++++++++++++++++++
float maxValue1 = 0;
float maxValue2 = 0;
float maxValue3 = 0;
float maxValue4 = 0;
float maxValue5 = 0;
//+++++++++++++++++++++++
/////////////
//int myArray[];
int  myArray[] = {maxValue1, maxValue2, maxValue3, maxValue4, maxValue5};
////////////
#include <LiquidCrystal.h>

LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

float val = 0;// define the variable as value=0

void setup()

{

  lcd.begin(16, 2);
  pinMode(PA7, INPUT);// input

}

void loop()
{
  val = analogRead(PA7);
  U1 = (val * 3.3) / 4.096;

  if (val > maxValue)
  {
    maxValue = val;
  }
  /*
    //+++++++++++++++++++
    if (val > maxValue1)
    {
    maxValue1 = val;
    }
    if (val > maxValue2)
    {
    maxValue2 = val;
    }
    if (val > maxValue3)
    {
    maxValue3 = val;
    }
    if (val > maxValue4)
    {
    maxValue4 = val;
    }
    if (val > maxValue5)
    {
    maxValue5 = val;
    }

    //++++++++++++++++++
  */
  ////////////

  if (val > maxValue1)
  {
    maxValue1 = val;
  }


  if (val != maxValue2)
  {
    maxValue2 = val;
  }

  if (val != maxValue3)
  {
    maxValue3 = val;
  }


  if (val != maxValue4)
  {
    maxValue4 = val;
  }


  if (val != maxValue5)
  {
    maxValue5 = val;
  }
  ////////////
  /*
    lcd.setCursor(0, 0);
    lcd.print(U1, 0); //Print the number of val on the LCD

    lcd.setCursor(5, 0);
    lcd.print(maxValue, 0);
  */
  //+++++++++++++++++++++++++
  lcd.print("     ");
  lcd.setCursor(0, 0);
  lcd.print(maxValue1, 0);
  lcd.setCursor(5, 0);
  lcd.print(maxValue2, 0);
  lcd.setCursor(10, 0);
  lcd.print(maxValue3, 0);
  lcd.setCursor(0, 1);
  lcd.print(maxValue4, 0);
  lcd.setCursor(5, 1);
  lcd.print(maxValue5, 0);
  //+++++++++++++++++++++++++

  delay(200); //Wait for 200ms

}

3 different
2 different numbers and two zeros
X, Y, 0, Y ,0

const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
//++++++++++++++++++++++
float maxValue1 = 0;
float maxValue2 = 0;
float maxValue3 = 0;
float maxValue4 = 0;
float maxValue5 = 0;
//+++++++++++++++++++++++
/////////////
//int myArray[];
int  myArray[] = {maxValue1, maxValue2, maxValue3, maxValue4, maxValue5};
////////////
#include <LiquidCrystal.h>

LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

float val = 0;// define the variable as value=0

void setup()

{

  lcd.begin(16, 2);
  pinMode(PA7, INPUT);// input

}

void loop()
{
  val = analogRead(PA7);
  U1 = (val * 3.3) / 4.096;

  if (val > maxValue)
  {
    maxValue = val;
  }
  /*
    //+++++++++++++++++++
    if (val > maxValue1)
    {
    maxValue1 = val;
    }
    if (val > maxValue2)
    {
    maxValue2 = val;
    }
    if (val > maxValue3)
    {
    maxValue3 = val;
    }
    if (val > maxValue4)
    {
    maxValue4 = val;
    }
    if (val > maxValue5)
    {
    maxValue5 = val;
    }

    //++++++++++++++++++
  */
  ////////////

  if (val > maxValue1)
  {
    maxValue1 = val;
  }

  if (val != maxValue2)
  {
    maxValue2 = val;
  }

  if (val != maxValue2)
  {
    maxValue3 = val;
  }


  if (val != maxValue3)
  {
    maxValue4 = val;
  }


  if (val != maxValue4)
  {
    maxValue5 = val;
  }
  ////////////
  /*
    lcd.setCursor(0, 0);
    lcd.print(U1, 0); //Print the number of val on the LCD

    lcd.setCursor(5, 0);
    lcd.print(maxValue, 0);
  */
  //+++++++++++++++++++++++++
  lcd.print("     ");
  lcd.setCursor(0, 0);
  lcd.print(maxValue1, 0);
  lcd.setCursor(5, 0);
  lcd.print(maxValue2, 0);
  lcd.setCursor(10, 0);
  lcd.print(maxValue3, 0);
  lcd.setCursor(0, 1);
  lcd.print(maxValue4, 0);
  lcd.setCursor(5, 1);
  lcd.print(maxValue5, 0);
  //+++++++++++++++++++++++++

  delay(200); //Wait for 200ms

}

2 different numbers

 ////////////

  if (val > maxValue1) //
  {
    maxValue1 = val;
  }

  if (val != maxValue1)//
  {
    maxValue2 = val;
  }

  if (val != maxValue2)//
  {
    maxValue3 = val;
  }


  if (val != maxValue3)//
  {
    maxValue4 = val;
  }


  if (val != maxValue4)//
  {
    maxValue5 = val;
  }
  ////////////

I did this way on LCD i have 2 different numbers ( A, B, A, B, A) instead of 5 - ( A, B, C, D, E ).

const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
//++++++++++++++++++++++
float maxValue1 = 0;
float maxValue2 = 0;
float maxValue3 = 0;
float maxValue4 = 0;
float maxValue5 = 0;
//+++++++++++++++++++++++
/////////////
//int myArray[];
int  myArray[] = {maxValue1, maxValue2, maxValue3, maxValue4, maxValue5};
////////////
int button = PB11;
#include <LiquidCrystal.h>

LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

float val = 0;// define the variable as value=0

void setup()

{

  lcd.begin(16, 2);
  pinMode(PA7, INPUT);// input
  pinMode(button, INPUT_PULLUP);

}

void loop()
{
  val = analogRead(PA7);
  U1 = (val * 3.3) / 4.096;
 
  ///////////
  if (val > maxValue1)
  {
    maxValue1 = val;       //1
  }

  if (val != maxValue1)
  {
    maxValue2 = val;      //2
  }

  if (val != maxValue2)
  {
    maxValue3 = val;     //3
  }


  if (val != maxValue3)
  {
    maxValue4 = val;      //4
  }


  if (val != maxValue4)
  {
    maxValue5 = val;      //5
  }
  //--------------
  if (digitalRead(PB11) == LOW)
  {
    maxValue1 = 0;
    maxValue2 = 0;
    maxValue3 = 0;
    maxValue4 = 0;
    maxValue5 = 0;      
  }
  //-----------
  ////////////
  /*
    lcd.setCursor(0, 0);
    lcd.print(U1, 0); //Print the number of val on the LCD

    lcd.setCursor(5, 0);
    lcd.print(maxValue, 0);
  */
  //+++++++++++++++++++++++++
  lcd.print("     ");
  lcd.setCursor(0, 0);
  lcd.print(maxValue1, 0);
  lcd.setCursor(5, 0);
  lcd.print(maxValue2, 0);
  lcd.setCursor(10, 0);
  lcd.print(maxValue3, 0);
  lcd.setCursor(0, 1);
  lcd.print(maxValue4, 0);
  lcd.setCursor(5, 1);
  lcd.print(maxValue5, 0);
  //+++++++++++++++++++++++++

  delay(200); //Wait for 200ms

}