Some help getting mpxPin A0 to update more often.
//PSPS for use in Arduino IDE. Corresponding ATMega328P-AU TQFP32 pin
int cutOut = 1; //31
int cutIn = 5; //32
int pumpPin = 6; //1
int solenoid = 4; // solenoid connected to digital pin 4 on arduino.
const int buttonPinOn = 1; // the pin that the ON pushbutton is attached to
const int buttonPinOff = 0; // the pin that the OFF pushbutton is attached to
int mpxVal = 0;
int mpxValBar = 0;
const int MIN_mpxPin= 0; //constraint stuff
const int MAX_mpxPin= 1023; //constraint stuff
const int MIN_mpxPinBar= 0; //constraint stuff
const int MAX_mpxPinBar= 7; //constraint stuff
int mpxPin = A0; //23
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd (7,8,9,10,11,12); //11RS,12E,13D4,14D5,15D6,16D7
// Variables will change:
int buttonPushCounterOn = 0; // counter for the number of button presses
int buttonPushCounterOff = 0; // counter for the number of button presses
int buttonStateOn = 0; // current state of the button
int buttonStateOff = 0; // current state of the button
int lastButtonStateOn = 0; // previous state of the On button
int lastButtonStateOff = 0; // previous state of the Off button */
//LED Stuff1of3
int led = 13; //16
void setup(){
pinMode(solenoid, OUTPUT); // sets the digital pins as in/output
pinMode(cutIn, INPUT);
pinMode(cutOut, INPUT);
pinMode(pumpPin, OUTPUT);
pinMode(buttonPinOn, INPUT);
pinMode(buttonPinOff, INPUT);
//LED Stuff2of3
pinMode(led, OUTPUT);
//Serial Stuff1of2
//Serial.begin(9600);
lcd.begin(16,2); // set up the LCD's number of columns and rows:
lcd.print("www.MISTFITZ.com"); // Print a message to the LCD.
delay(4000);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("-S.ON");
lcd.setCursor(10,1);
lcd.print("-M.OFF");
attachInterrupt(buttonPinOn, isr1 ,RISING);
attachInterrupt(buttonPinOff, isr2 ,RISING);
}
void isr1()
{
buttonPushCounterOn+=1;
if(buttonPushCounterOn > 60)buttonPushCounterOn =0; // rollover after 60.
lcd.setCursor(1,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(buttonPushCounterOn,DEC);
}
void isr2()
{
buttonPushCounterOff+=1;
if(buttonPushCounterOff > 60)buttonPushCounterOff =0; // rollover after 60.
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(buttonPushCounterOff,DEC);
}
void loop(){
//Read the MPX sensor *******************************
mpxVal = analogRead(mpxPin);
//Do the PSI /Bar maths
mpxVal = map(mpxVal*.98, MIN_mpxPin, MAX_mpxPin, 0,101);
mpxVal = constrain(mpxVal*.98, 0, 101);
mpxValBar = map(mpxVal*.98, MIN_mpxPin, MAX_mpxPin, 0,7);
mpxValBar = constrain(mpxValBar*.98, 0, 7);
//Serial Stuff2of2
//Serial.println(mpxVal, DEC); // Display pressure value.
//delay (400);
// On/Off Pressure Selection Switches
//ON LOGIChigh: If the "on" slide switch is HIGH (indicating we want on at 40) and the pressure is 40 or less the pump will turn on at 40.
if (digitalRead(cutIn) == HIGH && mpxVal <= 40){
digitalWrite(pumpPin, HIGH);
digitalWrite(led, HIGH);
}
//ON LOGIClow: But if the "on" slide switch is LOW (indicating we want on at 80)and pressure is 50 or less the pump will turn on at 50.
else if (digitalRead(cutIn) == LOW && mpxVal <= 50){
digitalWrite(pumpPin, HIGH);
digitalWrite(led, HIGH);
}
//OFF LOGIChigh: If the "off" slide switch is HIGH (indicating we want off at 60) and the pressure is 60 or greater the pump will turn on at 60.
if (digitalRead(cutOut) == HIGH && mpxVal >= 60){
digitalWrite(pumpPin, LOW);
digitalWrite(led, LOW);
}
//OFF LOGIClow: If the "off" slide switch is LOW (indicating we want off at 70) and the pressure is 70 or greater the pump will turn on at 70.
else if (digitalRead(cutOut) == LOW && mpxVal >= 70){
digitalWrite(pumpPin, LOW);
digitalWrite(led, LOW);
}
// Timing of the Solenoid
digitalWrite(solenoid, HIGH); // sets the solenoid on
digitalWrite(led, HIGH); // LEDturn the LED on
delay(buttonPushCounterOn * 1000); // buttonPushCounterOn * 1,000 = seconds. Solenoid opens and waits for __ seconds.
digitalWrite(solenoid, LOW); // sets the solenoid off
digitalWrite(led, LOW); // LED turn the LED off.
delay(buttonPushCounterOff * 1000); // buttonPushCounterOff * 60,000 = minutes. Solenoid closes and waits for __ min.
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print current pressure value: Bar
lcd.setCursor(9,0);
lcd.print(" ");
lcd.print(mpxValBar, DEC);
lcd.setCursor(12, 0);
lcd.print("Bar");
// print current pressure value: PSI
lcd.setCursor(1,0);
lcd.print(" ");
lcd.print(mpxVal, DEC);
lcd.setCursor(4, 0);
lcd.print("PSI / ");
delay (50);
}