#include <CAN.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_TFTLCD.h>
#include <SPI.h>
#include <Wire.h>
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GREY 0xD6BA
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
double VoutFL1 = 0;
double CurrentFL1 = 0;
double VoutFL2 = 0;
double CurrentFL2 = 0;
double VoutFL3 = 0;
double CurrentFL3 = 0;
double VoutFL4 = 0;
double CurrentFL4 = 0;
double VoutFL5 = 0;
double CurrentFL5 = 0;
double VoutFL6 = 0;
double CurrentFL6 = 0;
double VoutFL7 = 0;
double CurrentFL7 = 0;
double VoutFL8 = 0;
double CurrentFL8 = 0;
double VoutRL1 = 0;
double CurrentRL1 = 0;
double VoutRL2 = 0;
double CurrentRL2 = 0;
double VoutRL3 = 0;
double CurrentRL3 = 0;
double VoutRL4 = 0;
double CurrentRL4 = 0;
double VoutRL5 = 0;
double CurrentRL5 = 0;
double VoutRL6 = 0;
double CurrentRL6 = 0;
double VoutRL7 = 0;
double CurrentRL7 = 0;
double VoutRL8 = 0;
double CurrentRL8 = 0;
int BarPin = A0;
int BarVal = 0;
//const double scale_factor = 0.185; // 5A
const double scale_factor = 0.1; // 20A
//const double scale_factor = 0.066; // 30A
const double vRef = 5.00;
const double resConvert = 1024;
double resADC = vRef/resConvert;
double zeroPoint = vRef/2;
const int ButtonPin = 3;
int buttonPushCounter = 0; // counter for the number of button presses
boolean buttonState = LOW; // current state of the button
boolean lastButtonState = LOW; // previous state of the button
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
int analogValues[32] = {0}; // Array to store analog values for FL1-FL8, RL1-RL8, ES1-ES8, and BS1-BS8
int FL1 = analogValues[0] * 4.0117;
int FL2 = analogValues[1] * 4.0117;
int FL3 = analogValues[2] * 4.0117;
int FL4 = analogValues[3] * 4.0117;
int FL5 = analogValues[4] * 4.0117;
int FL6 = analogValues[5] * 4.0117;
int FL7 = analogValues[6] * 4.0117;
int FL8 = analogValues[7] * 4.0117;
int RL1 = analogValues[8] * 4.0117;
int RL2 = analogValues[9] * 4.0117;
int RL3 = analogValues[10] * 4.0117;
int RL4 = analogValues[11] * 4.0117;
int RL5 = analogValues[12] * 4.0117;
int RL6 = analogValues[13] * 4.0117;
int RL7 = analogValues[14] * 4.0117;
int RL8 = analogValues[15] * 4.0117;
int ES1 = analogValues[16] * 4.0117;
int ES2 = analogValues[17] * 4.0117;
int ES3 = analogValues[18] * 4.0117;
int ES4 = analogValues[19] * 4.0117;
int ES5 = analogValues[20] * 4.0117;
int ES6 = analogValues[21] * 4.0117;
int ES7 = analogValues[22] * 4.0117;
int ES8 = analogValues[23] * 4.0117;
int BS1 = analogValues[24] * 4.0117;
int BS2 = analogValues[25] * 4.0117;
int BS3 = analogValues[26] * 4.0117;
int BS4 = analogValues[27] * 4.0117;
int BS5 = analogValues[28] * 4.0117;
int BS6 = analogValues[29] * 4.0117;
int BS7 = analogValues[30] * 4.0117;
int BS8 = analogValues[31] * 4.0117;
void setup() {
// initialize the pushbutton pin as an input:
pinMode(ButtonPin, INPUT);
// Initialize ILI9341
tft.begin();
tft.setRotation(0); // Rotate display if needed (0, 1, 2, 3)
// Set text color and size
}
void loop() {
BarVal = analogRead(BarPin / 2);
tft.drawRect(100, A2, BarVal, 25, WHITE);
Serial.println(BarVal);
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(5, 5); // Set text position
tft.println("COOLANT");
tft.setTextColor(RED);
tft.setTextSize(3);
// Clear screen and display text
tft.setCursor(5, 23); // Set text position
tft.println("XXX'C");
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(200, 5); // Set text position
tft.println("OIL");
// Set text color and size
tft.setTextColor(BLUE);
tft.setTextSize(3);
// Clear screen and display tex
tft.setCursor(150, 23); // Set text position
tft.println("XXX'C");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(5);
// Clear screen and display text
tft.setCursor(78, 60); // Set text position
tft.println("XXX");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(98, 100); // Set text position
tft.println("KM/H");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(5, 300); // Set text position
tft.println("XX.X'C");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(140, 300); // Set text position
tft.println("XX.X BAR");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(140, 280); // Set text position
tft.println("XX.X AFR");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display text
tft.setCursor(5, 280); // Set text position
tft.println("XX.X V");
// Set text color and size
tft.setTextColor(RED);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(85, 260); // Set text position
tft.println("O");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(100, 260); // Set text position
tft.println("O");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(115, 260); // Set text position
tft.println("O");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(130, 260); // Set text position
tft.println("O");
// Set text color and size
tft.setTextColor(GREEN);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(145, 260); // Set text position
tft.println("O");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(115, 242); // Set text position
tft.println("O");
// read the state of the pushbutton value:
buttonState = digitalRead(ButtonPin);
Serial.println(buttonPushCounter);
switch (buttonPushCounter) // choose what to display based on buttonPushCounter value
{
case 0:
tft.drawCircle(120, 178, 60, YELLOW);
break;
case 1:
tft.drawRect(80, 120, 80, 120, WHITE);
tft.drawLine(130, 120, 158, 170, WHITE);
tft.drawLine(110, 120, 81, 170, WHITE);
tft.drawLine(158, 170, 81, 170, WHITE);
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 120); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 137); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 154); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 120); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 137); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 154); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 191); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 208); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(44, 225); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 191); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 208); // Set text position
tft.println("000");
// Set text color and size
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Clear screen and display tex
tft.setCursor(162, 225); // Set text position
tft.println("000");
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
if (buttonState != lastButtonState)
{
if (buttonState == HIGH)
{
// if the current state is HIGH then the button
// went from off to on:
buttonPushCounter++; // add one to counter
tft.fillScreen(BLACK);
if (buttonPushCounter > 5)
{
buttonPushCounter = 0;
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}