How to stop changes ?

After pressing the button pin #8 on LCD I have the same 3 values (assume ) 3.5V - voltage on A0.
I want to have no changes in maxVal ( continue to be 3.5V) when applied voltage is changed below or above 3.5V.
Please help

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int analogInput = 0;
const int vin;
const int potPin = A0; //Potentiometer input pin
const int ResetPin = 8; // resets maxVal and minVal both to current voltage
float maxVal = 0;
float minVal = 10;

void setup()
{
  lcd.begin(16, 2);
}

void loop()
{
  lcd.setCursor(6, 1); // set cursor to second row, first column
  delay(100); //wait 0.1 seconds
  if (digitalRead(ResetPin) == LOW)
  {
    minVal = maxVal = vin;
  }

  float vout = analogRead(analogInput) * 5.0 / 1024.0; // see text
  float vin = vout ;
  if (vin < 0.09)
  {
    vin = 0.0; //statement to quash undesired reading !
  }
  if (vin < minVal) minVal = vin;
  if (vin > maxVal) maxVal = vin;

  // DISPLAY
  lcd.setCursor(0, 0);
  lcd.print(vin, 2);  // the extra parameter 2 indicates the decimals
  lcd.print(" ");
  lcd.print(minVal, 2);
  lcd.print("-");
  lcd.print(maxVal, 2);
  lcd.setCursor(0, 2);
  delay(400);
}

It is hard to understand, what you want. But this code:

if (digitalRead(ResetPin) == LOW)
{
  minVal = maxVal = vin;
}

Is not gonna do what you want. "vin" is declared twice, once as an unassigned "const int" (can be anything) and once as a float that cannot be used by the above snippet (out of scope).

Problem 1:

const int vin;
 float vout = analogRead(analogInput) * 5.0 / 1024.0; // see text
  float vin = vout ;
  if (vin < 0.09)
  {
    vin = 0.0; //statement to quash undesired reading !
  }

You have 2 separate vin variables. It might not cause a problem but you should correct it

I want to have no changes in maxVal ( continue to be 3.5V) when applied voltage is changed below or above 3.5V.

If you don't want the value of maxVal to change then don't change it when it has the value that you require. In fact, why ever change it ? Set it to 3.5 to start with. By the way, maxVal is a strange name to give a variable that does not hold the maximum value

[quote author=ted link=msg=3713732 date=1525200725]

const int potPin = A0; //Potentiometer input pin
const int ResetPin = 8; // resets maxVal and minVal both to current voltage on A0

[/quote]

Starting voltage is not always the same, it is the voltage which exist on A0 when the button is pressed
Maybe original name maxVal is confusing, I should call it Vstart. I want torepleace maxVal by a new Vstart

You need a boolean variable, maybe calibrating, set to true initially. When the appropriate switch becomes pressed, set the variable to false.

Check the value in the variable before diddling with maxVal and/or minVal.

if (digitalRead(ResetPin) == LOW)
{
maxVal = vin;
}
else
{
maxVal = turnoff; // do nothing with maxVal, hold the value of it
}
What I need is a proper command to disable writing new values to maxVal after pressing the button.

PaulS:
You need a boolean variable, maybe calibrating, set to true initially. When the appropriate switch becomes pressed, set the variable to false.

Check the value in the variable before diddling with maxVal and/or minVal.

I am googling for it

ted:
if (digitalRead(ResetPin) == LOW)
{
maxVal = vin;
}
else
{
maxVal = turnoff; // do nothing with maxVal, hold the value of it
}
What I need is a proper command to disable writing new values to maxVal after pressing the button.

Regarding the comment:
do nothing with maxVal but assign it a value ?? If you don't want to do anything with maxVal, don't touch it !

ted:
I am googling for it

What are you googling for?

I think I find it - Arduino Programming Tutorials || How to "Stop" Void Loop - from that i learned - I need two loops main loop and inside it another for max Val, main is running when "if (digitalRead(ResetPin) == HIGH)" second one when " if (digitalRead(ResetPin) == LOW)"
Now I have to find out how to do that.

Tutorial

from that i learned - I need two loops

Nonsense.

bool calibrating = true;
int maxVal = -1000;
int minVal = +1000;
int prevState = HIGH;

void loop()
{
   int currState = digitalRead(calibratePin);
   if(currState != prevState)
   {
      if((currState == LOW)
      {
         // The properly wired switch became pressed
         calibrating = !calibrating;
      }
   }
   prevState = currState;

   int theVal = analogRead(somePin);

   if(calibrating)
   {
      if(theVal > maxVal)
         maxVal = minVal;
      if(theVal < minVal)
         minVal = theVal;
   }
}

One freaking loop (function).

You almost certainly don't want the loop() function to stop running. See reply #4 for the smart way to do it.

Create a global boolean variable, let's name it okToUpdate, and set it to true.
When you want to stop maxVal from being updated set okToUpdate to false
Test okToUpdate before changing the value of maxVal.
if it is true then update maxVal, otherwise don't.

Thanks Paul
What I did wrong ?

the errors
voltometr_min_max_6:11: error: conflicting declaration 'int maxVal'

int maxVal = -1000;

^

C:\Users\OWNER\Desktop\bibloteka\voltometr_min_max_6\voltometr_min_max_6.ino:8:7: note: previous declaration as 'float maxVal'

float maxVal = 0;

^

voltometr_min_max_6:12: error: conflicting declaration 'int minVal'

int minVal = +1000;

^

C:\Users\OWNER\Desktop\bibloteka\voltometr_min_max_6\voltometr_min_max_6.ino:9:7: note: previous declaration as 'float minVal'

float minVal = 10;

^

C:\Users\OWNER\Desktop\bibloteka\voltometr_min_max_6\voltometr_min_max_6.ino: In function 'void loop()':

voltometr_min_max_6:23: error: 'calibratePin' was not declared in this scope

int currState = digitalRead(calibratePin);

^

voltometr_min_max_6:27: error: expected ')' before '{' token

{

^

voltometr_min_max_6:31: error: expected primary-expression before '}' token

}

^

voltometr_min_max_6:34: error: 'somePin' was not declared in this scope

int theVal = analogRead(somePin);

^

voltometr_min_max_6:46: error: 'vin' was not declared in this scope

lcd.print(vin, 2); // the extra parameter 2 indicates the decimals

^

voltometr_min_max_6:54: error: expected '}' at end of input

}

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
Not used: C:\Users\OWNER\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.5 in folder: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
exit status 1
conflicting declaration 'int maxVal'

#include <LiquidCrystal.h>

//LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int analogInput = 0;
const int potPin = A0; //Potentiometer input pin
const int ResetPin = 8; // resets Tmin and Tmax both to current temperature T
float maxVal = 0;
float minVal = 10;
bool calibrating = true;
int maxVal = -1000;
int minVal = +1000;
int prevState = HIGH;
void setup()
{
  lcd.begin(16, 2);
}

void loop()
{

 {
   int currState = digitalRead(calibratePin);
   if(currState != prevState)
   {
      if((currState == LOW)
      {
         // The properly wired switch became pressed
         calibrating = !calibrating;
      }
   }
   prevState = currState;

   int theVal = analogRead(somePin);

   if(calibrating)
   {
      if(theVal > maxVal)
         maxVal = minVal;
      if(theVal < minVal)
         minVal = theVal;
   }

  // DISPLAY
  lcd.setCursor(0, 0);
  lcd.print(vin, 2);  // the extra parameter 2 indicates the decimals
  lcd.print(" ");
  lcd.print(minVal, 1);
  lcd.print("-");
  lcd.print(maxVal, 1);
  lcd.setCursor(0, 1);
  lcd.print(maxVal - vin);
  delay(400);
}

What I did wrong ?

float maxVal = 0;
float minVal = 10;
bool calibrating = true;
int maxVal = -1000;

You have 2 maxVal variables

And two minVal variables, too.

Thanks
Much less errors
C:\Users\OWNER\Desktop\bibloteka\voltometr_min_max_6\voltometr_min_max_6.ino: In function 'void loop()':

voltometr_min_max_6:28: error: expected ')' before '{' token

{

^

voltometr_min_max_6:32: error: expected primary-expression before '}' token

}

^

voltometr_min_max_6:47: error: 'vin' was not declared in this scope

lcd.print(vin, 2); // the extra parameter 2 indicates the decimals

^

voltometr_min_max_6:55: error: expected '}' at end of input

}

^

Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
Not used: C:\Users\OWNER\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
Using library LiquidCrystal at version 1.0.5 in folder: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
exit status 1
expected ')' before '{' token

Thanks
No errors
Testing

#include <LiquidCrystal.h>

//LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int analogInput = 0;
int vin;
const int potPin = A0; //Potentiometer input pin
const int ResetPin = 8; // resets
//float maxVal = 0;
//float minVal = 10;
const int calibratePin = 8;
bool calibrating = true;
int maxVal = -1000;
int minVal = +1000;
int prevState = HIGH;
void setup()
{
  lcd.begin(16, 2);
}

void loop()
{

 {
   int currState = digitalRead(calibratePin);
   if(currState != prevState);
   {
      if((currState == LOW))
      {
         // The properly wired switch became pressed
         calibrating = !calibrating;
      }
   }
   prevState = currState;

   int theVal = analogRead(8);

   if(calibrating)
   {
      if(theVal > maxVal)
         maxVal = minVal;
      if(theVal < minVal)
         minVal = theVal;
   }

  // DISPLAY
  lcd.setCursor(0, 0);
  lcd.print(vin, 2);  // the extra parameter 2 indicates the decimals
  lcd.print(" ");
  lcd.print(minVal, 1);
  lcd.print("-");
  lcd.print(maxVal, 1);
  lcd.setCursor(0, 1);
  lcd.print(maxVal - vin);
  delay(400);
}
}
void loop()
{

 {
   int currState = digitalRead(calibratePin);

Maybe you need to add some more curly braces...

i already did it so errors are gone.
Testing results

  1. button is on pin #8 with pull up resistor - not working, however reset button on board set up the numbers on LCD: "0X421 - 1000"
    (X space between numbers on LCD), after pressing the button all numbers should be thesame 421 - voltage on pin A0 - " 421 x421- 421"
    when voltage is changed the last number should not change but it is in strange vay.
    The first digit all the time is "0" the second is working ok as before, the third one strange behavior.

The strange behavior - when U in is reaching 5V the last number on the LCD is the same as minVal multiplied by 10
"0x317-3170"

  1. button is on pin #8 with pull up resistor - not working

Do you suppose that the layout, hole spacing, and trace positioning for the printed circuit boards that the Arduinos are built on were communicated to the manufacturer in a Word document?

Describing a schematic in non-technical terms (you did NOT sew a button onto the Arduino, did you?) is NOT useful information. A schematic IS.

however reset button on board set up the numbers on LCD: "0X421 - 1000"

Why on earth would you be pressing the reset switch on the Arduino?

after pressing the button all numbers should be thesame 421 - voltage on pin A0 - " 421 x421- 421"

Utter nonsense. The voltage on pin A0 sure as hell better not be 421 volts.

 lcd.print(vin, 2);  // the extra parameter 2 indicates the decimals
  lcd.print(" ");
  lcd.print(minVal, 1);
  lcd.print("-");
  lcd.print(maxVal, 1);

You look like a real idiot passing an int to function and adding comments that indicate how many decimal places to print. RTFM. When you pass an int, the second argument does NOT indicate how many decimal places.

Just my humble opinion.