Advertisement
Guest User

Land_Rover_LCD

a guest
Sep 21st, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.25 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>  //I2C lcd library
  2.  
  3. LiquidCrystal_I2C lcd(0x27, 20, 4); //define I2C address of lcd and define lcd type as twenty characters, four lines
  4.  
  5. #include <NMEAGPS.h> //include GPS library
  6.  
  7. NMEAGPS gps;
  8.  
  9. #define gps_port Serial
  10.  
  11. gps_fix currentFix;
  12.  
  13. const int menuPin = 4; //define pin 4 as the button to cycle the menu
  14.  
  15. byte menuState = 0; //current state of menu button press
  16. byte menuLastState = 0; //last state of menu button press
  17. byte menuCounter = 0; //create to store number of presses of menu button
  18.  
  19. void setup() {
  20.  
  21.   pinMode(menuPin, INPUT); //set the menu button pin to input
  22.   digitalWrite(menuPin, HIGH); //set the menu button pin to high
  23.    
  24.   gps_port.begin( 9600 ); //start the gps port
  25.   lcd.init(); //start the lcd
  26.   lcd.backlight(); //set the backlight on
  27.   lcd.setCursor(0, 0);
  28.   lcd.print( F("Initialising System") );  //start up message
  29.   lcd.setCursor(0, 2);
  30.   lcd.print(F("Please Wait..."));
  31.  
  32.  
  33.   delay(3000); // display the start up message for three seconds
  34.   lcd.clear(); //and then clear display
  35. }
  36.  
  37. void loop(){
  38.       while (gps.available( gps_port )) { //while the GPS port is available,
  39.       currentFix = gps.read(); //read the GPS
  40. }
  41.       menu(); //run the menu function
  42. }
  43.  
  44. void menu() {
  45.  
  46.   menuState = digitalRead(menuPin); //check if the menu button has been pressed
  47.   if(menuState != menuLastState)
  48.   {
  49.   if(menuState == 1)
  50.   {
  51.   menuCounter++; //increment the counter
  52.   }
  53.   if (menuState == 1)
  54.    
  55.   {
  56.   if(menuCounter==1) {
  57.     time(); //run the time function
  58.   }
  59.   if(menuCounter==2) {
  60.     position(); //run the position function
  61.   }
  62.   if(menuCounter==3) {
  63.     speed(); //run the speed function
  64.   }
  65.   if(menuCounter==4){
  66.     engine(); //place holder, currently non functional
  67.   }
  68.   if(menuCounter==5){
  69.   weather(); //place holder, currently non functional
  70.   }
  71.   if(menuCounter>4) menuCounter=0; //reset the counter to go back to the start
  72.   }
  73.   menuLastState = menuState; //remember the state of the button press
  74.   delay(20); //short delay for debouncing
  75.   }
  76. }
  77.  
  78.  
  79. void time() {
  80.     lcd.clear();
  81.     lcd.setCursor(0, 0);
  82.     lcd.print(F("Current Time & Date")); //display function title
  83.     if (currentFix.valid.time) { //if the signal is valid
  84.     lcd.setCursor(0,2);
  85.     if (currentFix.dateTime.hours < 10)  //to display a zero in front of single digit hours
  86.     lcd.print( '0' );
  87.     lcd.print(currentFix.dateTime.hours ); //display the hour
  88.     lcd.print( ':' );
  89.     if (currentFix.dateTime.minutes < 10) //to display a zero in front of single digit minutes
  90.     lcd.print( '0' );
  91.     lcd.print(currentFix.dateTime.minutes ); //display the minute
  92.     lcd.print( ':' );
  93.     if (currentFix.dateTime.seconds < 10) //to display a zero in front of single digit seconds
  94.     lcd.print( '0' );
  95.     lcd.print(currentFix.dateTime.seconds ); //display the seconds
  96.     lcd.print(F(" UTC")); //indicate time displayed is "UTC"
  97.     lcd.setCursor(0, 3);
  98.     if (currentFix.dateTime.date < 10) //to display zero in front of single digit date
  99.     lcd.print( '0' );
  100.     lcd.print(currentFix.dateTime.date ); //display date
  101.     lcd.print( '/' );
  102.     if (currentFix.dateTime.month < 10) //to display zero in front of single digit month
  103.     lcd.print( '0' );
  104.     lcd.print(currentFix.dateTime.month ); //display month
  105.     lcd.print( '/' );
  106.     if (currentFix.dateTime.year < 10) //to display zero in front of single digit year
  107.     lcd.print( '0' );
  108.     lcd.print(currentFix.dateTime.year ); //display year
  109.     }
  110. }
  111.  
  112. void position() {
  113.     lcd.clear();
  114.     lcd.setCursor(0, 0);
  115.     lcd.print(F("Position & Altitude")); //display function title
  116.     if (currentFix.valid.altitude) { //if signal is valid
  117.     lcd.setCursor(0, 1);
  118.     lcd.print(currentFix.altitude(), 2); //display altitude
  119.     lcd.print(F(" Metres"));   //in metres
  120.     }
  121.     if (currentFix.valid.location) { //if signal is valid
  122.     lcd.setCursor(0, 2);
  123.     lcd.print(currentFix.latitude(), 6); //display latitude to six decimal places
  124.     lcd.print(F(" Latitude"));
  125.     lcd.setCursor(0, 3);
  126.     lcd.print(currentFix.longitude(), 6); //display longitude to six decimal places
  127.     lcd.print(F(" Longitude"));
  128.     }
  129. }
  130.  
  131.  
  132. void speed() {
  133.     lcd.clear();
  134.     lcd.setCursor(0,0);
  135.     lcd.print(F("Speed & Heading")); //display function title
  136.     if (currentFix.valid.speed) { //if signal is valid
  137.     lcd.setCursor(0, 2);
  138.     lcd.print(currentFix.speed_mph(), 2); //display speed to two decimal places
  139.     lcd.print(F(" MPH")); //in miles per hour
  140.     lcd.setCursor(0, 3);
  141.     lcd.print(currentFix.heading(), 3); //display heading to three decimal places
  142.     lcd.print(F(" DEG")); //in degrees
  143.     }
  144. }
  145.  
  146.  void engine(){ //Temporary placeholder dummy function
  147.   lcd.clear();
  148.   lcd.setCursor(0, 0);
  149.   lcd.print(F("Engine Monitoring"));
  150.   lcd.setCursor(0, 1);
  151.   lcd.print(F("Coolant Temp:"));
  152.   lcd.setCursor(0, 2);
  153.   lcd.print(F("Eng' Oil Temp:"));
  154.   lcd.setCursor(0, 3);
  155.   lcd.print(F("G'box Oil Temp:"));
  156.  }
  157.  
  158.  void weather(){ //Temporary placeholder dummy function
  159.   lcd.clear();
  160.   lcd.setCursor(0,0);
  161.   lcd.print(F("Weather Conditions"));
  162.   lcd.setCursor(0, 1);
  163.   lcd.print(F("Temperature:"));
  164.   lcd.setCursor(0, 2);
  165.   lcd.print(F("Pressure:"));
  166.   lcd.setCursor(0, 3);
  167.   lcd.print(F("Humidity:"));
  168.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement