Guest User

Untitled

a guest
Jun 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <SoftwareSerial.h>
  3. #include <TinyGPS.h>
  4. #include <Servo.h>
  5. #include <EEPROM.h>
  6.  
  7. const int terminate_pin = 10;
  8. const int latch_pin = 8;
  9.  
  10. const long t_lat = 4066680.5;
  11. const long t_lon = -7398118.3;
  12.  
  13. //create Hardware objects
  14. TinyGPS gps;
  15. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  16. SoftwareSerial gps_serial(6,7);
  17. Servo servo;
  18.  
  19. bool solved; //Puzzle box solved? global for EEPROM reading
  20. float distance; //global for functions
  21.  
  22. void setup(){
  23.     solved = EEPROM.read(0);
  24.    
  25.     //LCD initialization
  26.     lcd.begin(16,2);
  27.    
  28.     //GPS initialization
  29.     gps_serial.begin(57600);
  30.     Serial.begin(115200);
  31.    
  32.     //Latch initialization
  33.     servo.attach(latch_pin);
  34.    
  35.     pinMode(terminate_pin,OUTPUT);      //terminate signal pin
  36. }
  37.  
  38. void loop(){
  39.     if (solved == 1) {
  40.         latch(1);
  41.         }else{
  42.         latch(0);
  43.     gps_serial.listen();
  44.    
  45.     while (gps.encode(gps_serial.read())){
  46.         lcd.print("Finding Signal...");
  47.         if (millis() > 6000){
  48.             lcd.clear();
  49.             lcd.println("No Signal");
  50.             digitalWrite(terminate_pin,HIGH);
  51.             }else{
  52.             lcd.clear();
  53.             lcd.println("Signal aquired");
  54.             static short c_time = millis();
  55.             while (millis() >= (c_time + 500)){}
  56.         }
  57.         long int lon, lat;
  58.         gps.get_position(&lon,&lat);
  59.         if (gps.distance_between(lon,lat,t_lon,t_lat)>=50){
  60.             latch(0);
  61.             }else{latch(1);}
  62.            
  63.     }
  64.     }
  65. }
  66.  
  67.  
  68. //controls the latch
  69. void latch(boolean op){
  70.     if (op == 1) {
  71.         lcd.println("Puzzle Solved!");
  72.         servo.write(90);
  73.         delay(5000);
  74.         servo.write(0);
  75.         }else{servo.write(0);
  76.             lcd.println("Wrong place");
  77.             delay(500);
  78.             digitalWrite(terminate_pin,HIGH);
  79.             }
  80.         }
Add Comment
Please, Sign In to add comment