/* In this version of the code only the GPS is polled and the Arduino serves as a pass-through for signals from the RC transmitter to the servos. Diane Brancazio 7/9/2014 www.dianemarie@alum.mit.edu */

/*---------------------------SET UP GPS SENSOR-----------------*/ GPS.begin(9600); // 9600 NMEA is the default baud rate for Adafruit MTK GPSs GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); // turn on only the "minimum recommended" data GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); /* Set the update rate to 1 Hz so the parsing code will have time to sort thru the data, and print it - (try higher if nec) */

// this code is between setup and loop// Interrupt is called once a millisecond, looks for any new GPS data, and stores itSIGNAL(TIMER0_COMPA_vect) { char c = GPS.read(); // if you want to debug, this is a good time to do it!#ifdef UDR0 if (GPSECHO) if (c) UDR0 = c; // writing direct to UDR0 is much much faster than Serial.print // but only one character can be written at a time. #endif}

// approximately every 2 seconds or so, print out the current stats if (millis() - timer > 2000) timer = millis(); // reset the timer pollSensors(); // delay(1000); ch1 = pulseIn(rudderIn, HIGH, 25000); // Read the pulse width of ch2 = pulseIn(sailwinchIn, HIGH, 25000); // each channel of receiver //syntax is pulseIn(pin, value, timeout) where value is HIgh or Low, and timeout is in ms // if(ch1>1000){Serial.println("Left Switch: Engaged");} //if(ch1<1000){Serial.println("Left Switch: Disengaged");} /* I found that Ch1 was my left switch and that it floats around 900 in the off position and jumps to around 1100 in the on position */Serial.print("Rudder:"); // Ch1 is rudderSerial.println(ch1); ch1 = min(max(ch1, 1000), 2000); //constrain value between 1000 and 2000, // rudderServo.write(map(ch1, 1000,2000,0,180)); // tell servo to go to position in variable 'pos'

Serial.print("y reading: "); Serial.print(event.magnetic.y); Serial.print(", x reading: "); Serial.println(event.magnetic.x); Serial.print("Compass Heading: "); Serial.println(heading); // in case you are not using the interrupt above, you'll // need to 'hand query' the GPS, not suggested :( // read data from the GPS in the 'main loop' // char c = GPS.read(); // // if you want to debug, this is a good time to do it! // if (GPSECHO) // if (c) Serial.print(c); // if a sentence is received, we can check the checksum, parse it... if (GPS.newNMEAreceived()) { // a tricky thing here is if we print the NMEA sentence, or data // we end up not listening and catching other sentences! // so be very wary if using OUTPUT_ALLDATA and trytng to print out data Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false return; // we can fail to parse a sentence in which case we should just wait for another }