#include <Adafruit_GFX.h>
#include <URTouch.h>
#include <UTFTGLUE.h>
URTouch myTouch(6,5,4,3,2);
UTFTGLUE myGLCD(0x9488,A2,A1,A3,A4,A0);
//Colours
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//LCD connection
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RST A4
//Font used
#if !defined(SmallFont)
extern uint8_t SmallFont[];
#elif !defined(BigFont)
extern uint8_t BigFont[];
#endif
int x,y;
int rpm;
int tempC;
int tempF;
char currentPage,selectedUnit;
const int speedPin=22;
const int tempPin=A15;
const int battPin=A14;
unsigned long prevmillis;
unsigned long duration;
unsigned long lcdrefresh;
boolean currentstate;
boolean prevstate;
void setup()
{
//Setup the LCD
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
drawHomeScreen();
currentPage='0';
selectedUnit='0';
//Setup Sensor
pinMode(speedPin,INPUT);
pinMode(tempPin,INPUT);
pinMode(battPin,INPUT);
prevmillis=0;
prevstate=LOW;
}
//HomeScreen
void drawHomeScreen()
{
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print("AUTOMOTIVE VISUAL", CENTER, 10);
myGLCD.setColor(255,255,255);
myGLCD.drawLine(0,32,480,32);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print("by AZIM SYAMIL", CENTER, 41);
myGLCD.setFont(BigFont);
myGLCD.print("Select Example", CENTER, 64);
//Button - Speed Sensor
myGLCD.setColor(255,0,0);
myGLCD.fillRoundRect(100,90,380,130);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(100,90,380,130);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(255,0,0);
myGLCD.print("SPEED SENSOR", CENTER, 110);
//Button - Temperature Sensor
myGLCD.setColor(255,0,0);
myGLCD.fillRoundRect(100,150,380,190);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(100,150,380,190);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(255,0,0);
myGLCD.print("TEMPERATURE SENSOR", CENTER, 170);
//Button - Battery Capacity
myGLCD.setColor(255,0,0);
myGLCD.fillRoundRect(100,210,380,250);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(100,210,380,250);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(255,0,0);
myGLCD.print("BATTERY CAPACITY", CENTER, 230);
}
void loop()
{
if (currentPage=='0')
{
if(myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
//Touch Speed
if((x>=100)&&(x<=380)&&(y>=90)&&(y<=130))
{
drawFrame(100,90,380,130);
currentPage='1';
myGLCD.clrScr();
drawSpeedSensor();
}
//Touch Temperature
if((x>=100)&&(x<=380)&&(y>=150)&&(y<=190))
{
drawFrame(100,150,380,190);
currentPage='2';
myGLCD.clrScr();
drawTemperatureSensor();
}
//Touch Battery
if((x>=100)&&(x<=380)&&(y>=210)&&(y<=250))
{
drawFrame(100,210,380,250);
currentPage='3';
myGLCD.clrScr();
drawBatteryCapacity;
}
}
}
if (currentPage=='1')
{
//ayat psal speed sensor
getSpeed();
if(myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y+myTouch.getY();
//Back Button
if ((x>=10)&&(x<=60)&&(y>=10)&&(y<=36))
{
drawFrame(10,10,60,36);
currentPage='0';
myGLCD.clrScr();
drawHomeScreen();
}
}
}
if (currentPage='2')
{
//ayat temperature sensor
getTemperature();
if(myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
//Back Button
if((x>=10)&&(x<=60)&&(y>=10)&&(y<=36))
{
drawFrame(10,10,60,36);
myGLCD.clrScr();
drawHomeScreen();
}
}
}
if(currentPage='3')
{
//ayat Battery Capacity
getBattery();
if(myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y-myTouch.getY();
//Back Button
if((x<=10)&&(x>=60)&&(y>=10)&&(y<=36))
{
drawFrame(10,10,60,36);
myGLCD.clrScr();
drawHomeScreen();
}
}
}
//Speed Sensor
void getSpeed()
{
//RPM Measurement
currentstate=digitalRead(speedPin);
if(prevstate !=currentstate)
{
if(currentstate==HIGH)
{
duration=(micros()-prevmillis);
rpm=(60000000/duration);
prevmillis=micros();
}
}
prevstate=currentstate;
if((millis()-lcdrefresh)>=100)
{
myGLCD.clrScr();
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print("SPEED of VEHICLE", CENTER, 10);
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print("RPM : ", CENTER, 25);
myGLCD.printNumI(rpm,130,145,3,'0');
lcdrefresh=millis();
}
}
//Temperature Sensor
void getTemperature()
{
int value=analogRead(tempPin);
float millivolts=(value/1024.0)*5000;
float celcius=millivolts/10;
myGLCD.clrScr();
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.printNumI(celcius,130,145,3,'0');
myGLCD.print("CELCIUS",CENTER, 200);
delay(1000);
}
void getBattery()
{
int voltReading=analogRead(battPin);
int volts=(voltReading/1023)*100;
myGLCD.clrScr();
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.printNumI(volts,130,145,3,'0');
delay(1000);
}
}
these are my coding.i hope u guys that can take a look at them. do tell me the mistakes.