//PSPS for use in Arduino IDE. Corresponding ATMega328P-AU TQFP32 pin
const int cutOut = 1; //31
const int buttonPinOff = 0; // the interrupt pin that the OFF interupt pushbutton is attached to
const int buttonPinOn = 1; // the interrupt pin that the ON interupt pushbutton is attached to
const int solenoid = 4; // solenoid connected to digital pin 4 on arduino.
int const cutIn = 5; //32
int const pumpPin = 6; //1
// 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
//LED Stuff1of3
int led = 13; //16
//PSI and Bar Stuff
int mpxVal = 0;
int mpxValBar = 0;
const int MIN_PSI= 0; //constraint stuff
const int MAX_PSI= 1023; //constraint stuff
const int MIN_Bar= 0; //constraint stuff
const int MAX_Bar= 7; //constraint stuff
int mpxPin = A0; //23
int mpxPin1 = A0; //23
// Variables will change:
volatile int buttonPushCounterOn = 0; // counter for the number of button presses
volatile int buttonPushCounterOff = 0; // counter for the number of button presses
volatile 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 */
unsigned long lastSwitchOnTime = 0; //Debounce Stuff
unsigned long lastSwitchOffTime = 0; //Debounce Stuff
long previousMillis = 0; // BLINK WITHOUT DELAY STUFF. Will store last time millis updated
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()
{
if(millis() - lastSwitchOnTime > 150) // Debounce: Ignore any events that happen within __ milliseconds of the last one
{
buttonPushCounterOn+=1;
if(buttonPushCounterOn > 60)buttonPushCounterOn =0; // rollover after 60.
}
lastSwitchOnTime = millis();
}
void isr2()
{
if(millis() - lastSwitchOffTime > 150) // Debounce: Ignore any events that happen within __ milliseconds of the last one
{
buttonPushCounterOff+=1;
if(buttonPushCounterOff > 60)buttonPushCounterOff =0; // rollover after 60.
}
lastSwitchOffTime = millis();
}
void loop(){
//Read the MPX sensor
mpxValBar = analogRead(mpxPin1);
mpxVal = analogRead(mpxPin);
//PSI /Bar maths.. incomplete
mpxVal = map(mpxVal * .98, MIN_PSI, MAX_PSI, 0, 101);
mpxVal = constrain(mpxVal, 0, 101);
mpxValBar = map(mpxValBar * .98, MIN_Bar, MAX_Bar, 0, 7);
mpxValBar = constrain(mpxValBar, 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 50)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);
}
//BLINK WITHOUT DELAY
{
unsigned long currentMillis = millis();
if(currentMillis > previousMillis) {
if(digitalRead(solenoid)){
digitalWrite(solenoid,LOW);
previousMillis = currentMillis + buttonPushCounterOff * 60000; // X 60000 for minutes.
}
else {
digitalWrite(solenoid,HIGH);
previousMillis = currentMillis + buttonPushCounterOn *1000; // X 1000 for seconds.
}
}
// (note: line 1 is the second row, since counting begins with 0):
// print current pressure value: PSI
lcd.setCursor(1,0);
lcd.print(" ");
lcd.setCursor(2, 0);
lcd.print(mpxVal, DEC);
lcd.print("PSI / ");
// print current pressure value: Bar
lcd.setCursor(9,0);
lcd.print(" ");
lcd.setCursor(12, 0);
lcd.print(mpxValBar, DEC);
lcd.print("Bar");
lcd.setCursor(1,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(buttonPushCounterOn,DEC);
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(buttonPushCounterOff,DEC);
}
}
Do you mean this part:
Alphafitz:
lcd.setCursor(12, 0);
lcd.print(mpxValBar, DEC);
lcd.print("Bar");
Perhaps there is not enough room in the last four characters of the line to put the number and the word "Bar"?