#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 8
#define TFT_RST 9
#define TFT_DC 10
int a,b,c;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup()
{
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void loop()
{
int pot1Value = analogRead(A0);
int pot2Value = analogRead(A1);
int pot3Value = analogRead(A2);
if(a!=pot1Value)
{
tft.fillRect(0, 10, tft.width(), 22, ILI9341_BLACK);
}
if(b!=pot2Value)
{
tft.fillRect(0, 100, tft.width(), 22, ILI9341_BLACK);
}
if(c!=pot3Value)
{
tft.fillRect(0, 190, tft.width(), 22, ILI9341_BLACK);
}
a=pot1Value;
b=pot2Value;
c=pot3Value;
tft.setCursor(0, 10);
tft.setTextColor(ILI9341_WHITE);
tft.print("Speed:");
if((map(pot1Value, 0, 1023, 0, 200))<80)
{
tft.setTextColor(ILI9341_GREEN);
}
else if((map(pot1Value, 0, 1023, 0, 200))>=80 && (map(pot1Value, 0, 1023, 0, 200))<150)
{
tft.setTextColor(ILI9341_YELLOW);
}
else
{
tft.setTextColor(ILI9341_RED);
}
tft.print(map(pot1Value, 0, 1023, 0, 200));
tft.print(" km/h");
tft.setCursor(0, 100);
tft.setTextColor(ILI9341_WHITE);
tft.print("Temperature:");
if((map(pot2Value, 0, 1023, 0, 100))<30)
{
tft.setTextColor(ILI9341_GREEN);
}
else if((map(pot2Value, 0, 1023, 0, 100))>=30 && (map(pot2Value, 0, 1023, 0, 100))<70)
{
tft.setTextColor(ILI9341_YELLOW);
}
else
{
tft.setTextColor(ILI9341_RED);
}
tft.print(map(pot2Value, 0, 1023, 0, 100));
tft.print(" C");
tft.setCursor(0, 190);
tft.setTextColor(ILI9341_WHITE);
tft.print("Battery:");
if((map(pot3Value, 0, 1023, 0, 100))<20)
{
tft.setTextColor(ILI9341_RED);
}
else if((map(pot3Value, 0, 1023, 0, 100))>=20 && ((map(pot3Value, 0, 1023, 0, 100)))<50)
{
tft.setTextColor(ILI9341_YELLOW);
}
else
{
tft.setTextColor(ILI9341_GREEN);
}
tft.print(map(pot3Value, 0, 1023, 0, 100));
tft.print("%");
}