#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
#define HIGH (1)
#define LOW (0)
const int pt1=A0; // pressure transducer tank psi
const int pt2=A1; // pressure transducer air bag
const int lvl=A2; // level sensor
const int rly1=3; // compressor
const int rly2=4; // air bag inflate
const int rly3=5; // air bag deflate
const int lvlu=556; // level sensor upper limit
const int lvll=466; // level sensor lower limit
const int llc=391; //compressor lower limit cut in
const int ulc=451; //compressor upper limit cut in I'm
const int mcp=782; // maximum compressor psi
const int apl= 421; // airbag pressure limit
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(115200);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A3, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
tft.begin();
tft.setCursor(1, 2);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("RAM Air Ride System!");
tft.setCursor(1, 60);
tft.setTextColor(ILI9341_ORANGE);
tft.setTextSize(1);
tft.println("Tank Pressure");
tft.setCursor(1, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(1);
tft.println("Air Bag Pressure");
tft.setCursor(200,100);
tft.setTextColor(ILI9341_ORANGE);
tft.setTextSize(2);
tft.println("PSI");
tft.setCursor(200, 200);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("PSI");
}
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
void loop() {
int pt1=analogRead(A0);
if (pt1 < mcp) {
tft.setCursor (22, 80);
tft.setTextColor(ILI9341_ORANGE);
tft.setTextSize(5);
tft.println(pt1 *.16617);
//delay(15);
tft.setCursor (22, 80);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(5);
tft.println(pt1 *.16617);
}
else {
tft.setCursor (22, 80);
tft.setTextColor(ILI9341_ORANGE);
tft.setTextSize(5);
tft.println("FAULT");
//delay(15);
tft.setCursor (22, 80);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize (5);
tft.println("FAULT");
}
int pt2=analogRead(A1);
if (pt2 < apl) {
tft.setCursor (22, 180);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(5);
tft.println(pt2 *.16617);
//delay(15);
tft.setCursor (22, 180);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(5);
tft.println(pt2 *.16617);
}
else {
tft.setCursor (22,180);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(5);
tft.println("FAULT");
//delay(15);
tft.setCursor (22, 180);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(5);
tft.println("FAULT");
digitalWrite(rly3, HIGH);
//delay (500);
}
int lvl=analogRead(A2);
if (lvl > lvlu){
digitalWrite(rly3, HIGH);
delay (500);
}
else {
digitalWrite(rly3, LOW);
}
lvl=analogRead(A2);
if (lvl < lvll){
digitalWrite(rly2, HIGH);
delay(500);
}
else{
digitalWrite(rly2, LOW);
}
if(pt1 > ulc) {
digitalWrite(rly1, LOW);
}
if(pt1 < llc){
digitalWrite(rly1, HIGH);
delay(500);
}
}