if ( zx_sensor.init() ) {
Serial.println("ZX Sensor initialization complete");
} else {
Serial.println("Something went wrong during ZX Sensor
init!");
}
// Read the model version number and ensure the library
will work
ver = zx_sensor.getModelVersion();
if ( ver == ZX_ERROR ) {
Serial.println("Error reading model version number");
} else {
Serial.print("Model version: ");
Serial.println(ver);
}
if ( ver != ZX_MODEL_VER ) {
Serial.print("Model version needs to be ");
Serial.print(ZX_MODEL_VER);
Serial.print(" to work with this library. Stopping.");
while(1);
}
// Read the register map version and ensure the library
will work
ver = zx_sensor.getRegMapVersion();
if ( ver == ZX_ERROR ) {
Serial.println("Error reading register map version num
ber");
} else {
Serial.print("Register Map Version: ");
Serial.println(ver);
}
if ( ver != ZX_REG_MAP_VER ) {
Serial.print("Register map version needs to be ");
Serial.print(ZX_REG_MAP_VER);
Serial.print(" to work with this library. Stopping.");
while(1);
}
}
void loop() {
// If there is position data available, read and print i
t
if ( zx_sensor.positionAvailable() ) {
x_pos = zx_sensor.readX();
if ( x_pos != ZX_ERROR ) {
Serial.print("X: ");
Serial.print(x_pos);
}
z_pos = zx_sensor.readZ();
if ( z_pos != ZX_ERROR ) {
Serial.print(" Z: ");
Serial.println(z_pos);
}
}
}
Run
Make sure you have the correct serial port selected under Tools → Serial
Port and "Arduino Uno" selected under Tools → Board. If you have never
used the Arduino IDE before, this turoial should get you started.
Page 8 of 16
Need help?
Do you have a question about the ZX Distance and Gesture Sensor and is the answer not in the manual?