Skip to content

Odometer

Tiogaplanet edited this page Oct 9, 2018 · 2 revisions

The odometer tracks the distance MiP has traveled.


readDistanceTravelled()

float readDistanceTravelled()

Description

Read the current MiP odometer tally.

Parameters

None

Returns

The distance travelled (in centimeters) since the last reset.

Notes

  • MiP's odometer is similar to that in a car. It maintains the total tally of the distance travelled, even across power cycles.
  • The resetDistanceTravelled() function can be used to reset the odometer.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("Odometer.ino - Read out current odometer reading and reset."));

  float cm = mip.readDistanceTravelled();
  Serial.print(F("MiP has travelled "));
    Serial.print(cm);
    Serial.println(F(" cm since the last reset."));

  mip.resetDistanceTravelled();

  Serial.println();
  Serial.println(F("Sample done."));
}

void loop() {
}

resetDistanceTravelled()

void resetDistanceTravelled()

Description

Reset MiP's odometer. The current odometer distance measurement is available by calling the readDistanceTravelled() function.

Parameters

None

Returns

Nothing

Notes

  • MiP's odometer doesn't automatically reset during a power cycle.
  • You should call this function if you want to manually reset it.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("Odometer.ino - Read out current odometer reading and reset."));

  float cm = mip.readDistanceTravelled();
  Serial.print(F("MiP has travelled "));
    Serial.print(cm);
    Serial.println(F(" cm since the last reset."));

  mip.resetDistanceTravelled();

  Serial.println();
  Serial.println(F("Sample done."));
}

void loop() {
}
Clone this wiki locally