void loop() { // This sketch displays information every time a new sentence is correctly encoded. while (ss.available() > 0) if (gps.encode(ss.read())) displayInfo(); if (millis() > 5000 && gps.charsProcessed() < 10) { Serial.println(F("No GPS detected: check wiring.")); while(true); } }
/*>>>>>>>>>>>>>>>>>>> 関数定義 <<<<<<<<<<<<<<<<<<*/ void gelay(unsigned long ms) { unsigned long start = millis(); do { while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); }
void TinyGPSCustom::begin(TinyGPSPlus &gps, const char *_sentenceName, int _termNumber) { lastCommitTime = 0; updated = valid = false; sentenceName = _sentenceName; termNumber = _termNumber; memset(stagingBuffer, '\0', sizeof(stagingBuffer)); memset(buffer, '\0', sizeof(buffer)); // Insert this item into the GPS tree gps.insertCustom(this, _sentenceName, _termNumber); }
int ReceiveGPSDatanormal(void) { static unsigned int ReceiveGPSNum = 0; static unsigned long lastTime = millis(); unsigned long nowTime = millis(); ReceiveGPSNum += ss.available(); while (ss.available()) gps.encode(ss.read()); if (ReceiveGPSNum >= 70) { while (ss.available()) ss.read(); ReceiveGPSNum = 0; if ((nowTime - lastTime) >= GPS_SAMPLING_RATE) { lastTime = millis(); return (AVAILABLE); } } return (UNAVAILABLE); }
void loop() { //Serial.print(F("Free RAM1:")); Serial.println(freeRam()); // Check secret button but = !digitalRead(ON_PIN); if(but){ Serial.println(F("Button pressed")); secret_button(); } bool GPS_debug = 0; unsigned long t = millis(); while (ss.available() > 0 || t + 1100 < millis()){ gps.encode(ss.read()); GPS_debug = 1; } if (GPS_debug) { Serial.println(F("GPS received")); GPS_debug = 0; } sats_fix = gps.satellites.value(); hdop = gps.hdop.value(); position_lat = gps.location.lat(); position_lon = gps.location.lng(); //target = 3; // debug distance = gps.distanceBetween(position_lat, position_lon, target_lat[target], target_lon[target]); //distance = 4; // debug static int sim, ok; #ifdef SIMULATION if (but == 1){ sim = 1; delay (1000); } else { sim = 0; lcd.setCursor(14, 1); lcd.print(target); } if (distance > 30 && sim == 0){ #else if (distance > 30) { #endif lcd_target(lcd, target, distance, sats_fix); } else { #ifdef BUTTON_FOR_NEXT_STEP wait finish; finish.set_time(2500); finish.set_steps(2); lcd.setCursor(0, 0); if(finish.step() == 1){ lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); } if (finish.step() == 2){ lcd.setCursor(0, 0); lcd.print(F("Press the button")); lcd.setCursor(0, 1); lcd.print(F("to continue... ")); } if (but == 1){ // Go to next target target++; ok = 1; } #else lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); target++; delay(5000); but = 0; #endif // Open the box at the end of game if(target > NUMBER_OF_TARGETS){ lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("CONRATULATIONS! ")); delay(5000); open_box(); } else { EEPROM.write(EEPROM_TARGET_INDEX, target); } } if(millis() > update_time + 1000){ update_time = millis(); Serial.println(gps.location.lat(), 6); Serial.print(F("LAT=")); Serial.println(gps.location.lat(), 6); Serial.print(F("LONG=")); Serial.println(gps.location.lng(), 6); Serial.print(F("ALT=")); Serial.println(gps.altitude.meters()); Serial.print(F("hdop=")); Serial.println(hdop); Serial.print(F("sats=")); Serial.println(sats_fix); if(hdop < 500 && sats_fix > 4){ fix = 1; distance = gps.distanceBetween(position_lat, position_lon, TARGET_1_LAT, TARGET_1_LON); } else{ fix = 0; strength = sats_fix; //lcd_gps_signal(lcd, strength); } } if(millis() > sleep_time + SLEEP_TIME_MS){ go_sleep(); } } void go_sleep(void) { lcd.clear(); lcd.print(F("Going to sleep..")); delay(2000); pinMode(ON_PIN, OUTPUT); digitalWrite(ON_PIN, 0); }