I tried the method you mentioned above, I think I'll just stick with the delay function to make it just a little simpler (for now this may change if the delay effects any other code).
Now I am trying to get the momentary buttons (with pulldown resistors) to activate the relays until a set pressure is reached (different pressure for all four sensors) I have started the digitalRead and Write commands in the code below, just unsure how to get it to inflate to a set pressure. Any ideas appreciated greatly. (The relay board is active low, so in order to activate the relays and the valves I have to pull the digital IO pin to ground. Also would it be possible to get a double tap of the momentary button to activate the function mentioned above? This would eliminate any accidental button pushes.
Thanks!
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float volts, psi, volts2, psi2, volts3, psi3, volts4, psi4;
const int button1Pin = 13;
const int relay1Pin = 2;
int button1State = 0;
void setup()
{
lcd.begin(20,4);
lcd.backlight();
pinMode(button1Pin, INPUT);
pinMode(relay1Pin, OUTPUT);
}
void loop()
{
//Displaying Values to LCD
int reading = analogRead(A0);
int reading2 = analogRead(A1);
int reading3 = analogRead(A2);
int reading4 = analogRead(A3);
volts = mapFloat(reading, 0, 1023, 0, 5);
psi = mapFloat(volts, 0.42, 4.5, 0, 100);
volts2 = mapFloat(reading2, 0, 1023, 0, 5);
psi2 = mapFloat(volts2, 0.42, 4.5, 0, 5);
volts3 = mapFloat(reading3, 0, 1023, 0, 5);
psi3 = mapFloat(volts3, 0.42, 4.5, 0, 5);
volts4 = mapFloat(reading4, 0, 1023, 0, 5);
psi4 = mapFloat(volts4, 0.42, 4.5, 0, 5);
int psiForLCD;
psiForLCD = psi;
int psiForLCD2;
psiForLCD2 = psi2;
int psiForLCD3;
psiForLCD3 = psi3;
int psiForLCD4;
psiForLCD4 = psi4;
lcd.setCursor(0,0);
lcd.print(" LF");
lcd.setCursor(0,1);
lcd.print(psiForLCD);
lcd.setCursor(16,0);
lcd.print(" RF");
lcd.setCursor(16,1);
lcd.print(psiForLCD2);
lcd.setCursor(0,2);
lcd.print(" LR");
lcd.setCursor(0,3);
lcd.print(psiForLCD3);
lcd.setCursor(16,2);
lcd.print(" RR");
lcd.setCursor(16,3);
lcd.print(psiForLCD4);
lcd.setCursor(8,1);
lcd.print("TANK");
lcd.setCursor(7,2);
lcd.print("XXX.XX");
delay(500);
lcd.clear();
//Reading Button 1
button1State = digitalRead(button1Pin);
if (button1State == HIGH){
digitalWrite(relay1Pin, LOW);
//Need a way of hitting the momentary button once and then relays being operated
//unitl a set pressure is reached by the sensors (different pressure for all 4 sensors)
//then each relay shutting off?? If possible a double tap of the button would be better.
}
else {
digitalWrite(relay1Pin, HIGH);
}
}