// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println("
");
Serial.println("SparkFun/GestureSense I2C Gesture Interrup
t");
Serial.println("Note: higher 'speed' numbers mean slower");
Serial.println("
");
// Initialize ZX Sensor (configure I2C and read model ID)
if ( zx_sensor.init(GESTURE_INTERRUPTS) ) {
Serial.println("ZX Sensor initialization complete");
} else {
Serial.println("Something went wrong during ZX Sensor ini
t!");
}
// Read the model version number and ensure the library wil
l 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 wil
l work
ver = zx_sensor.getRegMapVersion();
if ( ver == ZX_ERROR ) {
Serial.println("Error reading register map version numbe
r");
} 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);
}
// Initialize interrupt service routine
interrupt_flag = false;
zx_sensor.clearInterrupt();
attachInterrupt(INTERRUPT_NUM, interruptRoutine, RISING);
Serial.println("Interrupts now configured. Gesture away!");
}
void loop() {
// If we have an interrupt, read and print the gesture
if ( interrupt_flag ) {
Page 12 of 16
Need help?
Do you have a question about the ZX Distance and Gesture Sensor and is the answer not in the manual?