Include <EEPROM.H

Include <EEPROM.H

#include <EEPROM.h

#include <UTFT.h

#include <URTouch.h

#include<Servo.h

constint VCC = 13;

constinttrigPin = 11;

constintechoPin = 12;

constint VCC2 = 10;

constint trigPin2 = 8;

constint echoPin2 = 9;

constint led = A0;

constint led2 = A1;

Servo servo1;

Servo servo2;

long distance, duration, distance2, duration2;

constint buzzer = A8;

constint buzzer2 = A9;

#define C3 130.81

#define BPM 120

#define Q 6000/BPM

//==== Creating Objects

UTFT myGLCD(ILI9341_16,38,39,40,41);

URTouch myTouch( 6, 5, 4, 3, 2);

//==== Defining Variables

extern uint8_t Small;

extern uint8_t BigFont[];

extern uint8_t SevenSegNumFont[];

extern unsigned intdenver[15600];

int x, y;

char currentPage, selectedUnit, visorUp, visorDown;

void setup() {

pinMode(VCC, OUTPUT);

pinMode(VCC2, OUTPUT);

pinMode(trigPin, OUTPUT);

pinMode(trigPin2, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(echoPin2, INPUT);

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(buzzer, OUTPUT);

//pinMode(buzzer2, OUTPUT);

digitalWrite(VCC, HIGH);

digitalWrite(VCC2, HIGH);

servo1.attach(A2);

servo2.attach(A3);

myGLCD.InitLCD();

myGLCD.clrScr();

myTouch.InitTouch();

myTouch.setPrecision(PREC_MEDIUM);

drawHomeScreen();

currentPage = '0'; // Indicates that we are at Home Screen

}

void loop() {

if (currentPage == '0') {

getDistance();

if (myTouch.dataAvailable()) {

myTouch.read();

x=myTouch.getX(); // X coordinate where the screen has been pressed

y=myTouch.getY(); // Y coordinates where the screen has been pressed

// CAMERA

if ((x>=35) & (x<=285) & (y>=90) & (y<=130)) {

drawFrame(35, 90, 285, 130); // Custom Function -Highlighs the buttons when it's pressed

currentPage = '1'; // Indicates that we are the first example

myGLCD.clrScr(); // Clears the screen

drawWarning();

}

}

// MAPS

if ((x>=35) & (x<=285) & (y>=140) & (y<=180)) {

drawFrame(35, 140, 285, 180);

currentPage = '2';

myGLCD.clrScr();

drawMapOptions();

}

// Visor Control Button

if ((x>=35) & (x<=285) & (y>=190) & (y<=230)) {

drawFrame(35, 190, 285, 230);

currentPage = '3';

myGLCD.clrScr();

drawVisorControl();

}

}

// Warning

if (currentPage == '1') {

getDistance();

if (myTouch.dataAvailable()) {

myTouch.read();

x=myTouch.getX();

y=myTouch.getY();

}

// If we press the Back Button

if ((x>=10) & (x<=60) &(y>=10) & (y<=36)) {

drawFrame(10, 10, 60, 36);

currentPage = '0'; // Indicates we are at home screen

myGLCD.clrScr();

drawHomeScreen(); // Draws the home screen

}

}

// Denver Map

if (currentPage == '2') {

getDistance();

drawDenver();

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();

}

}

// Visor Control

if (currentPage == '3') {

getDistance();

if(myTouch.dataAvailable()){

myTouch.read();

x=myTouch.getX();

y=myTouch.getY();

if((x >=35) & (x <=285) & (y >= 45) & (y<=135)){

drawFrame(35, 45, 285, 135);

servoControlUp();

}

if((x>=35) & (x<=285) & (y>=140) & (y<=230)){

drawFrame(35, 140, 285, 230);

servoControlDown();

}

//Back Button

if((x>=10) & (x<=60) & (y>=10) & (y<=36)) {

drawFrame(10, 10, 60, 36);

currentPage = '0';

myGLCD.clrScr();

drawHomeScreen();

}

}

}

}

//======Custom Funtions ======

void servoControlUp(){

servo1.write(30);

servo2.write(40);

delay(1000);

}

void servoControlDown(){

servo1.write(40);

servo2.write(30);

delay(1000);

}

// drawHomeScreen - Custom Function

void drawHomeScreen() {

// Title

myGLCD.setBackColor(0,0,0); // Sets the background color of the area where the text will be printed to black

myGLCD.setColor(255, 255, 255); // Sets color to white

myGLCD.setFont(BigFont); // Sets font to big

myGLCD.print("Smart Helmet", CENTER, 10); // Prints the string on the screen

myGLCD.setColor(255, 255, 0); // Sets color to red

myGLCD.drawLine(0,32,319,32); // Draws the red line CHANGED TO LIME GREEN

myGLCD.setColor(255, 255, 255); // Sets color to white

myGLCD.setFont(BigFont); // Sets the font to small

myGLCD.print("Group 26", CENTER, 41); // Prints the string

// Button - Warning

myGLCD.setColor(16, 167, 103); // Sets green color

myGLCD.fillRoundRect (35, 90, 285, 130); // Draws filled rounded rectangle

myGLCD.setColor(255, 255, 255); // Sets color to white

myGLCD.drawRoundRect (35, 90, 285, 130); // Draws rounded rectangle without a fill, so the overall appearance of the button looks like it has a frame

myGLCD.setFont(BigFont); // Sets the font to big

myGLCD.setBackColor(16, 167, 103); // Sets the background color of the area where the text will be printed to green, same as the button

myGLCD.print("WARNING", CENTER, 102); // Prints the string

// Button - Denver Map

myGLCD.setColor(16, 167, 103);

myGLCD.fillRoundRect (35, 140, 285, 180);

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect (35, 140, 285, 180);

myGLCD.setFont(BigFont);

myGLCD.setBackColor(16, 167, 103);

myGLCD.print("DENVER MAP", CENTER, 152);

// Button -Visor Control

myGLCD.setColor(16, 167, 103);

myGLCD.fillRoundRect (35, 190, 285, 230);

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect (35, 190, 285, 230);

myGLCD.setFont(BigFont);

myGLCD.setBackColor(16, 167, 103);

myGLCD.print("VISOR CONTROL", CENTER, 202);

}

// Highlights the button when pressed

void drawFrame(int x1, int y1, int x2, int y2) {

myGLCD.setColor(255, 0, 0);

myGLCD.drawRoundRect (x1, y1, x2, y2);

while (myTouch.dataAvailable())

myTouch.read();

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect (x1, y1, x2, y2);

}

//======

void drawVisorControl(){

myGLCD.setColor(100, 155, 203);

myGLCD.fillRoundRect(10, 10, 60, 36);

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect(10, 10, 60, 36);

myGLCD.setFont(BigFont);

myGLCD.setBackColor(100, 155, 203);

myGLCD.print("<-", 18, 15);

myGLCD.setBackColor(0, 0 ,0);

myGLCD.setColor(160, 160, 160); // Sets green color

myGLCD.fillRoundRect (35, 45, 285, 135); // Draws filled rounded rectangle

myGLCD.setColor(255, 255, 255); // Sets color to white

myGLCD.drawRoundRect (35, 45, 285, 135); // Draws rounded rectangle without a fill, so the overall appearance of the button looks like it has a frame

myGLCD.setFont(BigFont); // Sets the font to big

myGLCD.setBackColor(160, 160, 160); // Sets the background color of the area where the text will be printed to green, same as the button

myGLCD.print("VISOR UP", CENTER, 90); // Prints the string

myGLCD.setColor(160, 160, 160);

myGLCD.fillRoundRect (35, 140, 285, 230);

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect (35, 140, 285, 230);

myGLCD.setFont(BigFont);

myGLCD.setBackColor(160, 160, 160);

myGLCD.print("VISOR DOWN", CENTER, 185);

}

void drawWarning() {

myGLCD.setColor(100, 155, 203);

myGLCD.fillRoundRect(10, 10, 60, 36);

myGLCD.setColor(255, 255, 255);

myGLCD.drawRoundRect(10, 10, 60, 36);

myGLCD.setFont(BigFont);

myGLCD.setBackColor(100, 155, 203);

myGLCD.print("<-", 18, 15);

myGLCD.setFont(BigFont);

myGlCD.setBackColor(0, 0, 0);

myGLCD.print("WARNING", CENTER, 110);

myGLCD.setColor(255, 255, 255);

myGLCD.print("Do NOT opperate", CENTER, 110);

myGLCD.print("while in motion!", CENTER, 130);

}

void drawMapOptions() {

//Title

myGLCD.setBackColor(0,0,0); // Sets the background color of the area where the text will be printed to black

myGLCD.setColor(255, 255, 255); // Sets color to white

myGLCD.setColor(255, 255, 0);

}

void getDistance() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if(distance <=10){// can change up to 400cm. for our purpose we left at 10cm.

digitalWrite(led, HIGH);

tone(buzzer2,C3,Q);

delay(100);

}

else{

digitalWrite(led, LOW);

}

long duration2, distance2;

digitalWrite(trigPin2, LOW);

delayMicroseconds(2);

digitalWrite(trigPin2, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin2, LOW);

duration2 = pulseIn(echoPin2, HIGH);

distance2 = (duration2/2) / 29.1;

if(distance2 <=10){//can change up to 400cm. four our purpose we left at 10cm.

digitalWrite(led2, HIGH);

tone(buzzer,C3,Q);

delay(100);

}

else{

digitalWrite(led2, LOW);

}

delay(100);

}

void drawDenver(){

myGLCD.drawBitmap(15, 15, 130, 120, denver, 2);

}