#include <Wire.h>
#include <skywriter.h>
#define PIN_TRFR 2 // TRFR Pin of Skywriter
#define PIN_RESET 3 // Reset Pin of Skywriter
/////////////debugleds///////
int led10 = 10;
int led11=11;
int led12= 12;
int led13 = 13;
long touch_timeout = 0;
int air_wheel_counter = 0;
void setup() {
Serial.begin(57600);
pinMode(led10,OUTPUT);
pinMode(led11,OUTPUT);
pinMode(led12,OUTPUT);
pinMode(led13,OUTPUT);
Skywriter.begin(PIN_TRFR, PIN_RESET);
// Bind skywriter events
Skywriter.onTouch(touch);
Skywriter.onAirwheel(airwheel);
Skywriter.onGesture(gesture);
}
void loop() {
Skywriter.poll(); // Poll for any updates from Skywriter
if( touch_timeout > 0 ) touch_timeout--;
}
void enter(){
}
void gesture(unsigned char type){
switch (type){
case SW_FLICK_WEST_EAST:
Serial.println(" SW_FLICK_WEST_EAST");
digitalWrite(led10,HIGH);
delay (100);
digitalWrite(led10,LOW);
break;
case SW_FLICK_EAST_WEST:
Serial.println(" EAST_WEST");
digitalWrite(led11,HIGH);
delay (100);
digitalWrite(led11,LOW);
break;
case SW_FLICK_SOUTH_NORTH:
Serial.println(" SOUTH_NORTH");
digitalWrite(led12,HIGH);
delay (100);
digitalWrite(led12,LOW);
break;
case SW_FLICK_NORTH_SOUTH:
Serial.println("NORTH_SOUTH");
digitalWrite(led13,HIGH);
delay (100);
digitalWrite(led13,LOW);
break;
}
}
void airwheel(int number){
if( air_wheel_counter > 5 ){// Prevent the command being run excessive times for negligible difference
if( number > 0 ){ // If the wheel's going in the "increase" direction
}
else{
}
air_wheel_counter = 0;
}
else{
air_wheel_counter++;
}
touch_timeout = 10000;
}
void touch(unsigned char type){
/*Serial.println("Got touch ");
Serial.print(type,DEC);
Serial.print('\n');*/
if( touch_timeout > 0 ) return; //Ensure that falsely detected touches within a small time interval of a real touch are ignored
switch (type) {
case SW_TOUCH_WEST:
Serial.println("SW_TOUCH_WEST");
break;
/* Launch selective area screenshot
* Alt-; is the keyboard shortcut I have it bound to
*/
case SW_TOUCH_SOUTH:
Serial.println("SW_TOUCH_SOUTH");
break;
/* Launch spotify web player
* Switch to chrome, open new tab, and start typing URL
*/
case SW_TOUCH_NORTH:
Serial.println("SW_TOUCH_NORTH");
break;
/* Launch facebook messenger
* Switch to chrome, open new tab, and start typing URL
*/
case SW_TOUCH_EAST:
Serial.println("SW_TOUCH_EAST");
break;
}
touch_timeout = 10000;
}