Skip to content

Commit

Permalink
Removed unused gestures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Hymel committed May 6, 2015
1 parent f150b9b commit 7892782
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 50 deletions.
29 changes: 13 additions & 16 deletions examples/I2C_Gesture_Demo/I2C_Gesture_Demo.ino
Expand Up @@ -6,7 +6,10 @@ May 6, 2015
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
Tests the ZX sensor's ability to read ZX data over I2C. This demo
configures the ZX sensor and periodically polls for gestures.
configures the ZX sensor and periodically polls for gestures. The
gesture is displayed along with its "speed" (how long it takes to
complete the gesture). Note that higher numbers of "speed"
indicate a slower speed.
Hardware Connections:
Expand Down Expand Up @@ -40,6 +43,7 @@ const int ZX_ADDR = 0x10; // ZX Sensor I2C address
// Global Variables
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
GestureType gesture;
uint8_t gesture_speed;

void setup() {

Expand All @@ -50,6 +54,7 @@ void setup() {
Serial.println();
Serial.println("----------------------------------------");
Serial.println("SparkFun/GestureSense - I2C Gesture Demo");
Serial.println("Note: higher 'speed' numbers mean slower");
Serial.println("----------------------------------------");

// Initialize ZX Sensor (configure I2C and read model ID)
Expand Down Expand Up @@ -96,30 +101,22 @@ void loop() {
// If there is gesture data available, read and print it
if ( zx_sensor.gestureAvailable() ) {
gesture = zx_sensor.readGesture();
gesture_speed = zx_sensor.readGestureSpeed();
switch ( gesture ) {
case NO_GESTURE:
Serial.println("No Gesture");
break;
case RIGHT_SWIPE:
Serial.println("Right Swipe");
Serial.print("Right Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
case LEFT_SWIPE:
Serial.println("Left Swipe");
Serial.print("Left Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
case UP_SWIPE:
Serial.println("Up Swipe");
break;
case HOVER:
Serial.println("Hover");
break;
case HOVER_LEFT:
Serial.println("Hover-Left");
break;
case HOVER_RIGHT:
Serial.println("Hover-Right");
break;
case HOVER_UP:
Serial.println("Hover-Up");
Serial.print("Up Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
default:
break;
Expand Down
29 changes: 13 additions & 16 deletions examples/I2C_Gesture_Interrupt/I2C_Gesture_Interrupt.ino
Expand Up @@ -8,6 +8,9 @@ https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Libr
Tests the ZX sensor's ability to read gesture data over I2C using
an interrupt pin. This program configures I2C and sets up an
interrupt to occur whenever the ZX Sensor throws its DR pin high.
The gesture is displayed along with its "speed" (how long it takes
to complete the gesture). Note that higher numbers of "speed"
indicate a slower speed.
Hardware Connections:
Expand All @@ -20,7 +23,7 @@ Hardware Connections:
2 DR Data Ready
Resources:
Include Wire.h and SFE_ZX_Sensor.h
Include Wire.h and ZX_Sensor.h
Development environment specifics:
Written in Arduino 1.6.3
Expand All @@ -44,6 +47,7 @@ const int INTERRUPT_NUM = 0; // Pin 2 on the UNO
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
volatile GestureType gesture;
volatile bool interrupt_flag;
uint8_t gesture_speed;

void setup() {

Expand All @@ -57,6 +61,7 @@ void setup() {
Serial.println();
Serial.println("---------------------------------------------");
Serial.println("SparkFun/GestureSense - I2C Gesture Interrupt");
Serial.println("Note: higher 'speed' numbers mean slower");
Serial.println("---------------------------------------------");

// Initialize ZX Sensor (configure I2C and read model ID)
Expand Down Expand Up @@ -116,30 +121,22 @@ void loop() {

// Read last gesture
gesture = zx_sensor.readGesture();
gesture_speed = zx_sensor.readGestureSpeed();
switch ( gesture ) {
case NO_GESTURE:
Serial.println("No Gesture");
break;
case RIGHT_SWIPE:
Serial.println("Right Swipe");
Serial.print("Right Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
case LEFT_SWIPE:
Serial.println("Left Swipe");
Serial.print("Left Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
case UP_SWIPE:
Serial.println("Up Swipe");
break;
case HOVER:
Serial.println("Hover");
break;
case HOVER_LEFT:
Serial.println("Hover-Left");
break;
case HOVER_RIGHT:
Serial.println("Hover-Right");
break;
case HOVER_UP:
Serial.println("Hover-Up");
Serial.print("Up Swipe. Speed: ");
Serial.println(gesture_speed, DEC);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion examples/I2C_ZX_Demo/I2C_ZX_Demo.ino
Expand Up @@ -18,7 +18,7 @@ Hardware Connections:
A5 CL I2C Clock
Resources:
Include Wire.h and SFE_ZX_Sensor.h
Include Wire.h and ZX_Sensor.h
Development environment specifics:
Written in Arduino 1.6.3
Expand Down
2 changes: 1 addition & 1 deletion examples/I2C_ZX_Interrupt/I2C_ZX_Interrupt.ino
Expand Up @@ -20,7 +20,7 @@ Hardware Connections:
2 DR Data Ready
Resources:
Include Wire.h and SFE_ZX_Sensor.h
Include Wire.h and ZX_Sensor.h
Development environment specifics:
Written in Arduino 1.6.3
Expand Down
104 changes: 104 additions & 0 deletions examples/UART_Gesture_Demo/UART_Gesture_Demo.ino
@@ -0,0 +1,104 @@
/****************************************************************
UART_Gesture_Demo.ino
XYZ Interactive ZX Sensor
Shawn Hymel @ SparkFun Electronics
May 6, 2015
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
Tests the ZX sensor's ability to read gesture data over UART using
SoftwareSerial. The ZX_Sensor library is needed for the
UART constants. As a result, we have to link the Wire library,
even though it is not used.
Hardware Connections:
Arduino Pin ZX Sensor Board Function
---------------------------------------
5V VCC Power
GND GND Ground
10 TX Data
Resources:
Include SoftwareSerial.h, Wire.h, and ZX_Constants.h
Development environment specifics:
Written in Arduino 1.6.3
Tested with a SparkFun RedBoard
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!
Distributed as-is; no warranty is given.
****************************************************************/

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ZX_Sensor.h>

// Global Variables
SoftwareSerial soft_serial(10, 11); // RX, TX
uint8_t c;

void setup() {

// Initialize hardware serial port. Note the baud rate.
Serial.begin(115200);
Serial.println();
Serial.println("-----------------------------------------");
Serial.println("SparkFun/GestureSense - UART Gesture Demo");
Serial.println("Note: higher 'speed' numbers mean slower");
Serial.println("-----------------------------------------");

// Initialize software serial port
soft_serial.begin(115200);
}

void loop() {

// Read in a character from the UART
if ( soft_serial.available() ) {
c = soft_serial.read();

// Determine type of message and print it
switch ( c ) {
case ZX_UART_GESTURE:

// Determine type of gesture
c = soft_serial.read();
switch ( c ) {
case RIGHT_SWIPE:
c = soft_serial.read();
Serial.print("Right Swipe. Speed: ");
Serial.println(c, DEC);
break;
case LEFT_SWIPE:
c = soft_serial.read();
Serial.print("Left Swipe. Speed: ");
Serial.println(c, DEC);
break;
case UP_SWIPE:
c = soft_serial.read();
Serial.print("Up Swipe. Speed: ");
Serial.println(c, DEC);
default:
break;
}

break;
case ZX_UART_ID:
Serial.print("Sensor type: ");
c = soft_serial.read();
Serial.print(c, DEC);
Serial.print(" HW version: ");
c = soft_serial.read();
Serial.print(c, DEC);
Serial.print(" FW version: ");
c = soft_serial.read();
Serial.println(c, DEC);
break;
default:
break;
}
}
}
100 changes: 100 additions & 0 deletions examples/UART_ZX_Demo/UART_ZX_Demo.ino
@@ -0,0 +1,100 @@
/****************************************************************
UART_ZX_Demo.ino
XYZ Interactive ZX Sensor
Shawn Hymel @ SparkFun Electronics
May 6, 2015
https://github.com/sparkfun/SparkFun_ZX_Distance_and_Gesture_Sensor_Arduino_Library
Tests the ZX sensor's ability to read ZX data over UART using
SoftwareSerial. The ZX_Sensor library is needed for the
UART constants. As a result, we have to link the Wire library,
even though it is not used.
Hardware Connections:
Arduino Pin ZX Sensor Board Function
---------------------------------------
5V VCC Power
GND GND Ground
10 TX Data
Resources:
Include SoftwareSerial.h, Wire.h, and ZX_Constants.h
Development environment specifics:
Written in Arduino 1.6.3
Tested with a SparkFun RedBoard
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!
Distributed as-is; no warranty is given.
****************************************************************/

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ZX_Sensor.h>

// Global Variables
SoftwareSerial soft_serial(10, 11); // RX, TX
uint8_t c;

void setup() {

// Initialize hardware serial port. Note the baud rate.
Serial.begin(115200);
Serial.println();
Serial.println("------------------------------------");
Serial.println("SparkFun/GestureSense - UART ZX Demo");
Serial.println("------------------------------------");

// Initialize software serial port
soft_serial.begin(115200);
}

void loop() {

// Read in a character from the UART
if ( soft_serial.available() ) {
c = soft_serial.read();

// Determine type of message and print it
switch ( c ) {
case ZX_UART_END:
Serial.println("End of stream");
break;
case ZX_UART_RANGES:
Serial.print("Ranges: ");
c = soft_serial.read();
Serial.print(c, DEC);
Serial.print(", ");
c = soft_serial.read();
Serial.println(c, DEC);
break;
case ZX_UART_X:
Serial.print("X: ");
c = soft_serial.read();
Serial.println(c, DEC);
break;
case ZX_UART_Z:
Serial.print("Z: ");
c = soft_serial.read();
Serial.println(c, DEC);
break;
case ZX_UART_ID:
Serial.print("Sensor type: ");
c = soft_serial.read();
Serial.print(c, DEC);
Serial.print(" HW version: ");
c = soft_serial.read();
Serial.print(c, DEC);
Serial.print(" FW version: ");
c = soft_serial.read();
Serial.println(c, DEC);
break;
default:
break;
}
}
}

1 comment on commit 7892782

@pelegren
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i installed the zx demo, the sensor can detect movements of my hand but in zx interrupt demo, it will not recognize my gesture. it keeps saying no gesture. please help.

Please sign in to comment.