Fair warning this is my first code that i have written. When i load this code on the Arduino and have it running through my LCD it runs fine for a little bit, then all of a sudden it seems like it jumps out of the loop and then starts doing whatever it wants. Did i miss something in my code. Any help/input would be great. Thank you in advance. I haven't hooked all the wires to the arduino yet, just the LCD serial wires.
//Read air pressure in air bags, 4 air pressure sensors on analog pins 0-3
//2 tank sensors connected to analog pins 4,5
//Air ride control unit attached to digital pin 13-6
//2 Push buttons connected digital Pins 2,3 to interrupt and clear display for upper and lower tank
//2 Push buttons connected digital Pins 5,4 to set ride heights
//Uses moderndevice 20x4 LCD screen
const int psisensor1 = 0; //Set LF Bag sensor input on Analog port 0
const int psisensor2 = 1; //Set RF Bag Sensor input on Analog port 1
const int psisensor3 = 2; //Set LR Bag Sensor input on Analog port 2
const int psisensor4 = 3; //Set RR Bag Sensor input on Analog port 3
const int tank1sensor = 4; //Set Upper Tank Sensor input on Analog port 4
const int tank2sensor = 5; //Set Lower Tank Sensor input on Analog Port 5
int sensor1val = 0; //Set LF Bag sensor to 0 value
int sensor2val = 0; //Set RF Bag sensor to 0 value
int sensor3val = 0; //Set LR Bag Sensor to 0 value
int sensor4val = 0; //Set RR Bag Sensor to 0 value
int tank1val = 0; //Set Upper Tank sensor to value 0
int tank2val = 0; //Set Lower Tank sensor to value 0
int press1 = 0;
int press2 = 0;
int press3 = 0;
int press4 = 0;
volatile int tank1pres = 0; //Set tank 1 pressure to 0
volatile int tank2pres = 0; //Set tank 2 pressure to 0
const int lfupPin = 13; //LF Bag fill solenoid to Digital Pin 13
const int lfdownPin = 12; //LF Bag release solenoid to Digital Pin 12
const int rfupPin = 11; //RF Bag fill solenoid to Digial Pin 11
const int rfdownPin = 10; //RF Bag release solenoid to Digital Pin 10
const int lrupPin = 9; //LR Bag fill solenoid to Digital Pin 9
const int lrdownPin = 8; //LR Bag release solenoid to Digital Pin 8
const int rrupPin = 7; //RR Bag fill solenoid to Digital Pin 7
const int rrdownPin = 6; //RR Bag release solenoid to Digital Pin 4
const int upbuttonPin = 5; //Push button to put car at highes level on Digital Pin 5
const int ridebuttonPin = 4; //Push button to put car at ride height on Digital Pin 4
int upbuttonState = LOW; // the current state of the output pin
int button1State; // the current reading from the input pin
int lastButton1State = HIGH; // the previous reading from the input pin
int ridebuttonState = LOW;
int button2State;
int lastbutton2State = HIGH;
long lastDebounceTime = 0;
long debounceDelay = 50;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, tank1, CHANGE);
attachInterrupt(1, tank2, CHANGE);
pinMode (lfupPin, OUTPUT);
pinMode (lfdownPin, OUTPUT);
pinMode (rfupPin, OUTPUT);
pinMode (rfdownPin, OUTPUT);
pinMode (lrupPin, OUTPUT);
pinMode (lrdownPin, OUTPUT);
pinMode (rrupPin, OUTPUT);
pinMode (rrdownPin, OUTPUT);
pinMode (upbuttonPin, INPUT);
pinMode (ridebuttonPin, INPUT);
Serial.print("?f"); //clear LCD per LCD117 command
Serial.print("?x05?y1Rhodes Caddy"); //print at column 6, row 2
Serial.print("?x06?y31950 Cadillac"); //print at column 7, row 4
delay (2000);
Serial.print("?f"); //clear LCD per LCD117 command
Serial.print("?x02?y0LF PSI:"); // print at column 4, row 1
Serial.print("?x12?y0RF PSI:"); //print at column 13, row 1
Serial.print("?x02?y2LR PSI:"); //print at column 4, row 3
Serial.print("?x12?y2RR PSI:"); //print at column 13, row 3
}
void loop()
{
sensor1val = analogRead(psisensor1); //reads all pressures in 4 bags
sensor2val = analogRead(psisensor2);
sensor3val = analogRead(psisensor3);
sensor4val = analogRead(psisensor4);
press1 = ((sensor1val)*35.0877-9.4737); //calculates pressure in bags from voltage
press2 = ((sensor2val)*35.0877-9.4737);
press3 = ((sensor3val)*35.0877-9.4737);
press4 = ((sensor4val)*35.0877-9.4737);
Serial.write(press1);
Serial.print("?x03?y1");
Serial.print(press1);
Serial.write(press2);
Serial.print("?x13?y1");
Serial.print(press2);
Serial.write(press3);
Serial.print("?x03?y3");
Serial.print(press3);
Serial.write(press4);
Serial.print("?x13?y3");
Serial.print(press4);
delay(200);
if (digitalRead(upbuttonPin)== HIGH)
{
if (press1 < 116);
{
delay(50);
digitalWrite(lfupPin, HIGH);
if (press1 >115);
{
delay(50);
digitalWrite(lfdownPin, HIGH);
}
}
if (press2 < 116);
{
delay(50);
digitalWrite(rfupPin, HIGH);
if (press2 > 115);
{
delay(50);
digitalWrite(rfdownPin, HIGH);
}
}
if (press3 < 116);
{
delay(50);
digitalWrite (lrupPin, HIGH);
if (press3 > 115);
{
delay(50);
digitalWrite (lrdownPin, HIGH);
}
}
if (press4 < 116);
{
delay(50);
digitalWrite(rrupPin, HIGH);
if (press4 > 115);
{
delay(50);
digitalWrite(rrdownPin, HIGH);
}
}
return;
}
if (digitalRead(ridebuttonPin) == HIGH)
{
if (press1 < 80);
{
delay(50);
digitalWrite (lfupPin, HIGH);
if (press1 > 80);
{
delay(50);
digitalWrite (lfdownPin, HIGH);
}
}
if (press2 < 80);
{
delay(50);
digitalWrite(rfupPin, HIGH);
if (press2 > 80);
{
delay(50);
digitalWrite(rfdownPin, HIGH);
}
}
if (press3 < 80);
{
delay(50);
digitalWrite(lrupPin, HIGH);
if (press3 > 80);
{
delay(50);
digitalWrite(lrdownPin, HIGH);
}
}
if (press4 < 80);
{
delay(50);
digitalWrite(rrupPin, HIGH);
if (press4 > 80);
{
delay(50);
digitalWrite(rrdownPin, HIGH);
}
}
return;
}
int reading1 = digitalRead(upbuttonPin);
if (reading1 != lastButton1State)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
button1State = reading1;
}
digitalWrite(upbuttonPin, button1State);
lastButton1State = reading1;
int reading2 = digitalRead(ridebuttonPin);
if (reading2 != lastbutton2State)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
button2State = reading2;
}
digitalWrite(ridebuttonPin, button2State);
lastbutton2State = reading2;
}
void tank1() //Interrupt Button on digital pin 2 to show Tank 1 Pressure
{
Serial.print("?x5?y0");
Serial.print("UPPER TANK PSI:");
tank1val = analogRead(tank1sensor);
tank1pres =((tank1val)*35.0877-9.4737);
Serial.print("?x08?y1");
Serial.write(tank1pres);
Serial.print(tank1pres);
}
void tank2() //Interrupt Button on digital pin 3 to show Tank 2 pressure
{
Serial.print("?x05?y2");
Serial.print("LOWER TANK PSI:");
tank2val = analogRead(tank2sensor);
tank2pres =((tank2val)*35.0877-9.4737);
Serial.print("?x08?y3");
Serial.write(tank2pres);
Serial.print(tank2pres);
}