Hello all,
My project will not compile - I keeping getting errors for missing declarations. ('pressureSamples' was not declared in this scope") I'm trying to open a solenoid in a pressurized closed loop air system when all arithmetic and clock functions have been met. Can you please check out my below code and let me know what you think. It could be a simple mistake but I'm open to criticism if it is haha. I'm still new to programming and like to learn from my mistakes ..please help if you can:
#include <Wire.h> //enables communication between I2C devices
#include <LiquidCrystal_I2C.h> //enables interface with LCD screen
const int pressureInput = A0; //selects the analog pin for the pressure transducer
const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 100; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set up baud rate for the serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
int RelayPin = 4; //This is the output valve on the Arduino
int dropPerSecondInPressure = pressureSamples[0] - pressureSamples[2];
unsigned long currentTime = millis();
static unsigned long intervalStart = 0;
static float pressureSamples[3];
// initial Time display is 12:59:45 PM
int h=12;
int m=59;
int s=45;
int flag=1; //PM
// Time Set Buttons
int button1;
int button2;
int hs=0;// pin 0 for Hours Setting
int ms=1;// pin 1 for Minutes Setting
float pressureValue = 0; //this is the variable to store the value coming from the pressure transducer
LiquidCrystal_I2C lcd(0x27, 20, 4); //sets the LCD I2C communication address; format(address, columns, rows)
void setup() // enter setup code here to run once when system is energized or reset
{
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second (bps)
lcd.begin(); //initializes LCD screen
pinMode(hs,INPUT_PULLUP);// no need of Pullup resistor for Button 1
pinMode(ms,INPUT_PULLUP);
pinMode(RelayPin, OUTPUT); //Sets the valve as an output
float pressurePSI;//Sets the valve as an output
}
void loop() //loop routine runs repeatedly forever
{
unsigned long currentTime = millis();
static unsigned long intervalStart = 0;
static float pressureSamples[3];
int readPressurePSI();
int dropPerSecondInPressure = pressureSamples[0] - pressureSamples[2]; // "three consecutive samplings" = 2 intervals = 1 second.
if (currentTime - intervalStart >= (1000 / 2)) // samples air pressure twice per second.
{
intervalStart = currentTime;
float pressurePSI = readPressurePSI();
pressureSamples[0] = pressureSamples[1];
pressureSamples[1] = pressureSamples[2];
pressureSamples[2] = pressurePSI;
if (dropPerSecondInPressure > 0.1) // drop exceeding a rate of 0.1 psi (0, 007 bar) per second,
{
digitalWrite(RelayPin, LOW); // signals a 24vdc solenoid to de-energize (go LOW)
}
{
pressureValue = analogRead(pressureInput); //reads given value from input pin and assigns it to a variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //this is the conversion equation used to convert analog readings to psi
Serial.print(pressureValue, 1); //this prints the value from the previous line to serial
Serial.println("psi"); //this prints the label to serial
lcd.setCursor(0,8); //sets the cursor to column 0, row 8
lcd.print("Pressure:"); //prints the label
lcd.print(pressureValue, 1); //prints the pressure value to the LCD screen 1 digit on float
lcd.print("psi"); //prints the lable after value
lcd.print(" "); //clears the display after large values or negatives
delay(sensorreadDelay); //is a delay in milliseconds between read values
lcd.setCursor(0,2); // Print TIME in Hour, Min, Sec + AM/PM
lcd.print("Time:");
if(h<10)lcd.print("0"); // always 2 digits
lcd.print(h);
lcd.print(":");
if(m<10)lcd.print("0");
lcd.print(m);
lcd.print(":");
if(s<10)lcd.print("0");
lcd.print(s);
if(flag==0) lcd.print("AM");
if(flag==1) lcd.print("PM");
lcd.setCursor(0,4);// for Line 2
lcd.print(" QRS/Dump Valve II ");
// Set loop execution time to 1000ms
// This makes also the LCD display freeze for 1000ms
delay(987);// gives the 1 sec tick ( take account of loop time, so delay is not 1000 )
// this method of measuring time cannot gives a good accuracy
// expect max. drift of 1/1000 , max 3.6 Sec per hour
// measured drift 1.3 s per hour
s=s+1; //increment sec. counting lcd.clear(); not needed
/-------Time setting-------/
button1=digitalRead(hs);
if(button1==0) h=h+1;
button2=digitalRead(ms);
if(button2==0){
s=0;
m=m+1;
}
/* ---- manage seconds, minutes, hours am/pm overflow ----*/
if(s==60){
s=0;
m=m+1;
}
if(m==60){
m=0;
h=h+1;
}
if(h==13){
h=1;
flag=flag+1;
if(flag==2)flag=0;
}
}
}
}