theres a few problems that are easy to spot
like lcd.begin(20, 4); only needs to be done once in set up
using i is a bad idea as it looks like a one
repeating the same lcd prints 11 times
adding
lcd.clear (); all over the place even though the lcd didn't change (that causes flashing)
adding same library twice
#include <LiquidCrystal.h>
posting as a note pad instead of attaching as a file
see if this is any better (haven't changed your code just moved things about)
#include <LiquidCrystal.h>
int analogInPin = A2;
const float Null = 0.50; // Null VDC; datasheet Page 32.
const float Sensitivity = 13.33; // Sensitivity mV/psi; datasheet Page 32.
int SwitCont = 13; // This stage is extra due to the fact of extra information....LED connected to digital pin 13.
int pinButton = 8; // Pushbutton connected to digital pin 5.
int pinValve = 6; // Solenoid valve pin number assigned.
int pinMotor = 7; // 12V DC motor pin number assigned.
int hold = 0;
int count = 1;
int prevcount = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
float pressuremmHg = 0;
float pressure = 0;
void setup()
{
pinMode(13, OUTPUT); // Pin mode setup for the switch controller.
pinMode(8, INPUT); // Input of the switch.
pinMode (7, OUTPUT); // Pin mode setup for the DC motor.
pinMode (6, OUTPUT); // Pin mode setup for the Solenoid valve.
lcd.begin(20, 4); // lcd rows and columns
lcd.clear ();
lcd.setCursor(0, 1);
lcd.print("Current Pressure in"); // title of sorts
lcd.setCursor(0, 2);
lcd.print("The Air Chamber"); // title of sorts
}
void loop() //Begining of the loop counter.
{
if (digitalRead (pinButton) == HIGH)
{
float pressurePSI, pressureVDC; // Initializtions.
pressure = analogRead(analogInPin); // Reading Information
pressureVDC = (float)pressure * 0.0048828125; // (5V/1024 (digital counts) = 0.0048828125) 1024 is the maximun voltage at 5V and 0 is the 0V.
pressureVDC = pressureVDC - Null; // Sensor Calculations.
pressurePSI = pressureVDC / Sensitivity * 1000;
pressuremmHg = pressurePSI - 0.15 ;
if (count != 12) {//same screen up till 12
if (count != prevcount) {
//only if count changed clear once
lcd.clear ();
}
lcd.setCursor(0, 1);
lcd.print("Current Pressure in"); // title of sorts
lcd.setCursor(0, 2);
lcd.print("The Air Chamber"); // title of sorts
lcd.setCursor(6, 4);
lcd.print(pressuremmHg);
lcd.print("mmHg ");
delay(10);
prevcount = count;
}
switch (count)
{
case 1:
digitalWrite (6, HIGH);
delay (300);
digitalWrite (7 , HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure > 140)
{
hold = 0;
}
}
digitalWrite (6, LOW);
digitalWrite (7 , LOW);
delay (2000);
count = 2;
break;
case 2:
digitalWrite (6, HIGH);
digitalWrite (7 , HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure > 210)
{
hold = 0;
}
}
digitalWrite (6, LOW);
digitalWrite (7 , LOW);
delay (2000);
count = 3;
break;
case 3:
digitalWrite (6, HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 170)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 4;
break;
case 4:
digitalWrite (6, HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 105)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 5;
break;
case 5:
digitalWrite (6, HIGH );
digitalWrite (7, HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure > 400)
{
hold = 0;
}
}
digitalWrite (6, LOW);
digitalWrite (7 , LOW);
delay (2000);
count = 6;
break;
case 6:
digitalWrite (6, HIGH );
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 105)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 7;
break;
case 7:
digitalWrite (6, HIGH );
digitalWrite (7, HIGH);
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure > 920)
{
hold = 0;
}
}
digitalWrite (6, LOW);
digitalWrite (7 , LOW);
delay (2000);
count = 8;
break;
case 8:
digitalWrite (6, HIGH );
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 896)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 9;
break;
case 9:
digitalWrite (6, HIGH );
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 871)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 10;
break;
case 10:
digitalWrite (6, HIGH );
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 842)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 11;
break;
case 11:
digitalWrite (6, HIGH );
hold = 1;
while (hold)
{
pressure = analogRead(analogInPin);
if (pressure < 105)
{
hold = 0;
}
}
digitalWrite (6, LOW);
delay (2000);
count = 12;
break;
case 12:
digitalWrite (6, HIGH);
delay (1000);
digitalWrite (6, LOW);
digitalWrite (7, LOW);
delay(10000);
break;
}
}
}