Gentlemen,
I need some insight into a variable problem so I come here for your help.
I'm in the process of building a pressure regulator. My Pthresh is defined in the beginning as a value of 1030, which is displayed onto the LCD. Depending on the LED or state of a button, Pthresh should be updated to either a 1015 or 1040 value. In order to confirm that Pthresh is being updated, I output the value to serial monitor, which displays the correct value depending on the button state, BUT the value does not update on the LCD screen. The value of the LCD screen will subsequently activate a relay.
In essence, my problem is that while my Pthresh that was defined in the beginning was 1030, it's being updated and displayed on serial monitor, but not being displayed and updated on my LCD screen. Any thoughts on where I may went wrong with the code or possible suggestions?
#include <SFE_BMP180.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#define ALTITUDE 1655.0
SFE_BMP180 pressure;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Button = 10;
int Debounce = 0;
int led = 13;
int led2 = 9;
const int Debounce_thresh = 10;
boolean ButtonPressed = false;
boolean Toggle = false;
const int relayPin = 8;
int Pthresh = 1030;
void setup()
{
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(Button, INPUT);
digitalWrite(led, HIGH);
digitalWrite(led2, LOW);
Serial.begin(9600);
Serial.println("REBOOT");
pinMode(relayPin, OUTPUT);
lcd.begin(16, 2);
lcd.print("PROJECT - ALPHA");
delay(5000);
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever.
}
}
void loop() {
if(digitalRead(Button)==HIGH)
{
Debounce++;
//Serial.println("Green");
} else
{
Debounce = 0;
ButtonPressed = false;
Toggle = false;
// Serial.println("Red");
}
if (Debounce >= Debounce_thresh)
{
ButtonPressed = true;
}
if(ButtonPressed == true && Toggle == false)
{
Toggle = true;
digitalWrite(led, !digitalRead(led));
digitalWrite(led2, !digitalRead(led2));
}
if(digitalRead(led)==HIGH)
{
const int Pthresh = 1015;
Serial.println();
Serial.print("Pthresh: ");
Serial.print(Pthresh, DEC);
}
if(digitalRead(led2)==HIGH)
{
const int Pthresh = 1040;
Serial.println();
Serial.print("Pthresh: ");
Serial.print(Pthresh, DEC);
}
char status;
double T,P;
if (P> Pthresh) {
digitalWrite(relayPin, LOW);
}
else {
digitalWrite(relayPin,HIGH);
}
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure.getPressure(P,T);
if (status != 0)
{
lcd.setCursor (0, 1);
lcd.print("Pab_m:");
lcd.setCursor (6, 1);
lcd.print(P*0.0295333727,2);
lcd.println(" inHg");
delay(50);
lcd.setCursor (0, 0);
lcd.print("P_thr:");
lcd.print(Pthresh*0.0295333727,2);
lcd.println(" inHg");
}
}
}
}
delay(50); // Pause for 5 seconds.
}