Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <SoftwareSerial.h>
- #include <TinyGPS.h>
- #include <Servo.h>
- #include <EEPROM.h>
- const int terminate_pin = 10;
- const int latch_pin = 8;
- const long t_lat = 4066680.5;
- const long t_lon = -7398118.3;
- //create Hardware objects
- TinyGPS gps;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- SoftwareSerial gps_serial(6,7);
- Servo servo;
- bool solved; //Puzzle box solved? global for EEPROM reading
- float distance; //global for functions
- void setup(){
- solved = EEPROM.read(0);
- //LCD initialization
- lcd.begin(16,2);
- //GPS initialization
- gps_serial.begin(57600);
- Serial.begin(115200);
- //Latch initialization
- servo.attach(latch_pin);
- pinMode(terminate_pin,OUTPUT); //terminate signal pin
- }
- void loop(){
- if (solved == 1) {
- latch(1);
- }else{
- latch(0);
- gps_serial.listen();
- while (gps.encode(gps_serial.read())){
- lcd.print("Finding Signal...");
- if (millis() > 6000){
- lcd.clear();
- lcd.println("No Signal");
- digitalWrite(terminate_pin,HIGH);
- }else{
- lcd.clear();
- lcd.println("Signal aquired");
- static short c_time = millis();
- while (millis() >= (c_time + 500)){}
- }
- long int lon, lat;
- gps.get_position(&lon,&lat);
- if (gps.distance_between(lon,lat,t_lon,t_lat)>=50){
- latch(0);
- }else{latch(1);}
- }
- }
- }
- //controls the latch
- void latch(boolean op){
- if (op == 1) {
- lcd.println("Puzzle Solved!");
- servo.write(90);
- delay(5000);
- servo.write(0);
- }else{servo.write(0);
- lcd.println("Wrong place");
- delay(500);
- digitalWrite(terminate_pin,HIGH);
- }
- }
Add Comment
Please, Sign In to add comment