Skip to content

Instantly share code, notes, and snippets.

@jatkins
Created May 10, 2012 20:10
Show Gist options
  • Save jatkins/2655566 to your computer and use it in GitHub Desktop.
Save jatkins/2655566 to your computer and use it in GitHub Desktop.
#include <LiquidCrystal.h>
#include <SD.h>
#include <Keypad.h>
#include <Servo.h>
const int chipSelect = 53; // SD pin
const char gpsTag[] = "$GPRMC"; // Start of GPS command
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const byte ROWS = 4;
const byte COLS = 3;
char nav_keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte col_pins[COLS] = { 31, 30, 32 };
byte row_pins[ROWS] = { 33, 35, 34, 36 };
Keypad pad = Keypad(makeKeymap(nav_keys), row_pins, col_pins, ROWS, COLS);
Servo base;
int menu = 0;
int seconds = 0;
const int shutter = 12;
const int focus = 13;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
base.attach(10);
lcd.begin(16,2);
delay(200);
Serial1.println("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
delay(200);
Serial1.println("$PMTK220,1000*1F");
pinMode(53, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
if(!SD.begin(chipSelect)) {
lcd.print("SD failed!");
delay(1000);
lcd.clear();
lcd.print("AutoPod");
lcd.setCursor(0,1);
lcd.print("Select Menu 1-X");
return;
}
lcd.print("SD initialized");
delay(1000);
lcd.clear();
lcd.print("AutoPod");
lcd.setCursor(0,1);
lcd.print("Select Menu 1-X");
}
void loop() {
char key = pad.getKey();
if(key != NO_KEY){
menu = (int)key - 48;
updateLcd(menu);
}
if(menu == 1){
char shutter = pad.getKey();
if(shutter != NO_KEY){
if(shutter=='*'){
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
} else if(shutter=='#'){
digitalWrite(12, HIGH);
delay(50);
digitalWrite(12, LOW);
}
}
} else if(menu == 2){
int seconds =+ (int)pad.getKey()-48;
updateLcd(menu);
} else if(menu == 9){
updateLcd(menu);
delay(1000);
}
}
String poll_gps() {
String gps = "";
String gps_return = "";
while(Serial1.available()) {
gps += String((char)Serial1.read());
}
if(check_gps(gps)==1){
if(gps[18]=='A'){
gps_return = String(time(gps.substring(7, 13)) + " - " + date(gps.substring(56, 62)) + " - " + lat(gps.substring(20, 32)) + " - " + lng(gps.substring(32, 44)));
return gps_return;
} else {
//lcd.clear();
//lcd.print("No Lock!");
gps_return = "No GPS Lock!";
}
}
}
int check_gps(String data){
for(int i=0;i<6;i++){
if(data[i]!=gpsTag[i]){
return 0;
}
}
return 1;
}
String date(String gps_date) {
String day = gps_date.substring(0,2);
String month = gps_date.substring(2,4);
String year = gps_date.substring(4,6);
String date = String(month + "-" + day + "-" + "20" + year);
return date;
}
String time(String gps_time) {
String hour = gps_time.substring(0,2);
String miniute = gps_time.substring(2,4);
String second = gps_time.substring(4,6);
String time = String(hour + ":" + miniute + ":" + second);
return time;
}
String lat(String gps_lat) {
String deg = gps_lat.substring(0, 2);
String minutes = gps_lat.substring(2, 4);
String decimal = gps_lat.substring(5, 9);
String heading = gps_lat.substring(10, 11);
String lat = String(deg + " " + minutes + " " + decimal + heading);
return lat;
}
String lng(String gps_lng) {
String deg = gps_lng.substring(0,3);
String minutes = gps_lng.substring(3, 5);
String decimal = gps_lng.substring(6, 10);
String heading = gps_lng.substring(11, 12);
String lng = String(deg + " " + minutes + " " + decimal + heading);
return lng;
}
String get_keys() {
char key = pad.getKey();
if(key != NO_KEY) {
Serial.println(key);
}
}
void updateLcd(int menu) {
if(menu == 0){
lcd.clear();
lcd.print("AutoPod");
lcd.setCursor(0,1);
lcd.print("Select Menu 1-X");
} else if(menu == 1) {
lcd.clear();
lcd.print("Press * to focus");
lcd.setCursor(0,1);
lcd.print("Press # to fire");
} else if(menu == 2) {
int seconds;
lcd.clear();
lcd.print("Enter time delay");
lcd.setCursor(0,1);
lcd.print(seconds);
} else if(menu == 9) {
lcd.clear();
lcd.print("GPS");
lcd.setCursor(0,1);
//lcd.autoscroll();
//String GPS = poll_gps();
//char *gps;
//GPS.toCharArray(gps, GPS.length());
//for (int i = 0; i < 10; i++) {
lcd.print(poll_gps());
//delay(500);
//lcd.noAutoscroll();
//lcd.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment