Here is the code sorry about that:
//Car Multi-Gauge Project
//Version: 1.0.0
//Author: Ryan St. John
#include <LiquidCrystal.h>
#include <LcdBarGraph.h>
#include "max6675.h"
//Menu and Display Settings
int select = 1; //The number of the page that should be visible
int maxPages = 3; //The max number of pages
int Contrast = 90, //The brightness and contrast of the LCD display
bg = 55;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Initialize the LCD library with the correct interface pins
//Boost Settings and Declarations
int boostSensorPin = A5; //The pin that is connected with the boost sensor
double atmPressure = 0.0; //Where the measure atmospheric pressure will be stored
double boostPeak = 0.0; //Where the max measured boost (in PSI) will be stored
//Exhaust Gas Temperature Settings
int thermoDO = 13;
int thermoCS = 10;
int thermoCLK = 9;
int vccPin = 8; //The power pin for the max chip
double tempPeak = 0.0; //Where the max recorded temperature will be stored
double tempAverage = 0.0; //Where the average temperature will be stored
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//Meth Injection Settings
int relayPin = A0; //The pin that is connected to the meth relay
int switchPressure = 4; //The PSI required to turn on the meth injection
//Interrupt Settings
int nextPagePin = A2; //The pin used to control which page is displayed
int nextPageSupplyPin = A1; //The pin supplying the high voltage
//Custom LCD display characters
byte thermometerChar[8] = { B00100, B01010, B01010, B01110, B01110, B11111, B11111, B01110 };
byte degreeChar[8] = { B01100, B10010, B10010, B01100, B00000, B00000, B00000, B00000 };
byte thermometerAvgChar[8] = { B11111, B00000, B00100, B01010, B01010, B01110, B11111, B01110 };
void setup()
{
pinMode(13,OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(nextPagePin,INPUT);
pinMode(nextPageSupplyPin,OUTPUT);
digitalWrite(nextPageSupplyPin, 100);
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, HIGH);
//Set Final Contrast and BG Level
analogWrite(6,Contrast);
analogWrite(9,bg);
while(atmPressure == 0.00)
calibrateAtmosphericPressure();
//Show the welcome message
welcomeDisplay();
//If atmospheric pressure didn't calibrate right set it to the average atmospheric pressure
if((atmPressure > 14.50) && (atmPressure < 15.10))
{
lcd.setCursor(0, 0);
lcd.print("---Calibrated---");
lcd.setCursor(4, 1);
lcd.print(atmPressure);
lcd.setCursor(9, 1);
lcd.print("psi");
}else{
atmPressure = 14.6959;
lcd.setCursor(0, 0);
lcd.print("---Defaulting---");
lcd.setCursor(4, 1);
lcd.print(atmPressure);
lcd.setCursor(9, 1);
lcd.print("psi");
}
delay(1000);
lcd.setCursor(0, 0);
lcd.clear();
}
void loop()
{
//Check and see if next page button is pressed
if(analogRead(nextPagePin) > 1000){
delay(300);
lcd.clear();
select++;
}
if((select > maxPages))
{
//Trying to go to a page that doesn't exist so loop back through the pages starting at 1
select = 1;
}
//Boost page selected
if(select == 1)
{
double boost = readBoost();
if(boost > boostPeak)
{
boostPeak = boost;
}
if(boost > 0){
if(boost > 8) { boost = 8; }
String bar = "";
for (double i = 0; i < boost; i = i + 0.5)
{
bar = bar + "|";
}
lcd.print(bar);
}
if(boost < 0){
lcd.setCursor(0,0);
lcd.print(boost);
lcd.setCursor(4,0);
lcd.print("vac");
}else{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(1,0);
lcd.print(boost);
lcd.setCursor(4,0);
lcd.print("psi");
}
lcd.setCursor(8,0);
lcd.print("Peak:");
lcd.setCursor(13,0);
lcd.print(boostPeak);
//Exhaust Temperature Selected
}else if(select == 2){
//Create the custom characters
lcd.createChar(0, thermometerChar);
lcd.createChar(1, degreeChar);
lcd.createChar(2, thermometerAvgChar);
int temp = readExhaustGasTemperature();
lcd.setCursor(0,0);
lcd.write(byte(0));
lcd.setCursor(1,0);
lcd.print(temp);
lcd.setCursor(5,0);
lcd.write(byte(1));
lcd.setCursor(6,0);
lcd.print("F");
lcd.setCursor(8,0);
lcd.write(byte(2));
lcd.setCursor(9,0);
lcd.print(tempAverage);
lcd.setCursor(13,0);
lcd.write(byte(1));
lcd.setCursor(14,0);
lcd.print("F");
lcd.setCursor(0,1);
lcd.write(byte(0));
lcd.setCursor(1,1);
lcd.print("max");
lcd.setCursor(5,1);
lcd.print(tempPeak);
lcd.setCursor(9,1);
lcd.write(byte(1));
lcd.setCursor(10,1);
lcd.print("F");
//Meth Injection Selected
}else if(select == 3){
double boost = readBoost();
if(boost < 0){
lcd.setCursor(0,0);
lcd.print(boost);
lcd.setCursor(4,0);
lcd.print("vac");
}else{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(1,0);
lcd.print(boost);
lcd.setCursor(4,0);
lcd.print("psi");
}
lcd.setCursor(8,0);
lcd.print(" Set:");
lcd.setCursor(13,0);
lcd.print(switchPressure);
if(boost >= switchPressure)
{
digitalWrite(relayPin, HIGH);
lcd.setCursor(0,1);
lcd.print("Injecting Meth!");
}else{
digitalWrite(relayPin, LOW);
lcd.setCursor(0,1);
lcd.print("Meth System Idle");
}
}
delay(300);
lcd.clear();
}
void calibrateAtmosphericPressure()
{
//Set the sensor pin to input
pinMode(boostSensorPin, INPUT);
//Read the raw value of the pressure sensor
int rawValue = analogRead(boostSensorPin);
double change, last;
//Take a reading a wait
last = analogRead(boostSensorPin);
delay(250);
//Wait for sensor to stabalize
do
{
double readSens = analogRead(boostSensorPin);
change = readSens - last;
last = readSens;
delay(50);
}while(change != 0);
//Convert the raw data of the atmospheric pressure to PSI
atmPressure = (last*(.00488)/(.022)+20) * 0.14503773773020923;
//Debugging
//Serial.print("Atmospheric Pressure: ");
//Serial.println(atmPressure);
}
void welcomeDisplay()
{
//Set up the number of lines and columns on the LCD
lcd.begin(16, 2);
//Move the cursor to the middle of the first line
lcd.setCursor(4, 0);
//Display the message
lcd.print("Welcome");
//Set the contrast to max so we can fade in
int cont = 255;
//Fade BG and Contrast in
for(int i = 0; i <115; i++)
{
if(cont > 115){
cont = cont - 8;
}
analogWrite(6, cont);
analogWrite(9,i);
delay(15);
}
//Set Normal Contrast and BG Level
analogWrite(6,Contrast);
analogWrite(9,115);
delay(500);
//Set the contrast to fade out from
cont = Contrast;
//Fade BG and Contrast out
for(int i = 115; i > 55; i--)
{
if(cont < 255)
{
cont = cont + 1;
}
analogWrite(9,i);
analogWrite(6, cont);
delay(30);
}
//Clear the welcome message
lcd.setCursor(4, 0);
lcd.print(" ");
//Set Final Contrast and BG Level
analogWrite(6,Contrast);
analogWrite(9,bg);
}
double readBoost()
{
//Define our return holder
double boost = 0.0;
//Read the raw data from the pressure sensor
int raw = analogRead(boostSensorPin);
//Convert the raw data into PSI and then subtract it from the atmospheric pressure
boost = ((raw*(.00488)/(.022)+20) * 0.14503773773020923) - atmPressure;
return boost;
}
int readExhaustGasTemperature()
{
//Define our return holder
int tmp = 0;
//Read the raw data from the temperature sensor
tmp = thermocouple.readFahrenheit();
//Keep a record of the average temperature
if(tmp > 0)
{
tempAverage = ((tempAverage + tmp)/2);
}
//Keep a record of the max temperature reached
if(tmp > tempPeak)
{
tempPeak = tmp;
}
return tmp;
}