//Values for the LEDs
//top
int ledPin1 = 7;
//right
int ledPin2 = 8;
//bottom
int ledPin3 = 9;
//left
int ledPin4 = 10;
//center
int ledPin5 = 11;
//power
int ledPinP = 13;
//Sensor Pins
//Accelerometer Analog Input
int sensorPinZ = 0;
int sensorPinY = 1;
int sensorPinX = 2;
//Values for sensosrs
int valX = 0;
int valY = 0;
int valZ = 0;
//values for gesture recognition
int testVal = 111;
int newMotion[100];
int swirl[100] = {
561,598,598,547,593,592,534,588,587,521,581,581,508,574,575,497,568
,568,486,565,563,472,562,559,464,559,557,458,557,555,452,557,553,444,
555,551,442,548,548,435,556,552,392,551,547,395,541,542,458,554,549,
443,572,561,426,574,567,410,584,576,416,595,585,420,605,595,416,610,
602,409,613,606,401,608,604,393,603,600,397,603,599,406,600,597,
417,600,596,422,598,594,428,594,592,440,592,590,450,585,583,458};
int shake[100] = {
538,537,524,537,537,529,535,534,532,535,534,531,535,530,528,534,531,
528,536,529,529,535,531,527,533,529,526,529,528,525,530,529,525,529,
529,526,525,529,526,525,531,524,523,533,525,520,533,527,517,537,530,
513,541,533,516,543,535,513,544,537,512,546,538,515,542,539,515,546,
539,515,545,539,513,541,538,512,537,536,510,535,533,505,532,532,504,
530,528,502,528,526,499,526,521,498,523,519,490,527,519,485};
boolean swirlGate = false;
boolean shakeGate = false;
void setup () {
//Declaring input and output
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPinP, OUTPUT);
pinMode(sensorPinX, INPUT);
pinMode(sensorPinY, INPUT);
pinMode(sensorPinZ, INPUT);
//Setting up serial
//Serial.begin(9600);
}
void recognizeSwirl(){
for(int z = 0; z < 100; z++){
//check new array to old
testVal = abs(newMotion[z] - swirl[z]);
Serial.println(testVal);
if(testVal<100) { swirlGate = true; } else { swirlGate = false; z = 100; }
}
}
void recognizeShake(){ for(int z = 0; z > 100; z++){
//check new array to old
testVal = abs(newMotion[z] - shake[z]);
if(testVal<90) { shakeGate = true; }
else { swirlGate = false; z = 100; }
}
}
//This function is used to light the correct LED
//The timing on the light is rough rated to a slow breath
void lightMe(int l1) {
//PWM ramp up for (int i=1; i<400; i++) {
digitalWrite(l1, HIGH); delayMicroseconds(i);
digitalWrite(l1, LOW); delayMicroseconds(i);
delay(3); }
//PWM ramp down for (int i=399; i>0; i--) {
digitalWrite(l1, HIGH);
delayMicroseconds(i);
digitalWrite(l1, LOW);
delayMicroseconds(i);
delay(3);
}
}
void otherlightMe() {
for (int i=0; i<10; i++) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delayMicroseconds(i);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delayMicroseconds(i);
delay(5);
}
for (int i=0; i<10; i++) {
digitalWrite(ledPin5, HIGH);
delayMicroseconds(i);
digitalWrite(ledPin5, LOW);
delayMicroseconds(i);
delay(5);
}
}
void loop(){
digitalWrite(ledPinP,HIGH);
for(int i=0; i<100; i=i+3) {
newMotion[i] = analogRead(sensorPinX);
newMotion[i+1] = analogRead(sensorPinY);
newMotion[i+2] = analogRead(sensorPinZ);
}
recognizeSwirl();
recognizeShake();
if (swirlGate == true) {
lightMe(ledPin1);
lightMe(ledPin2);
lightMe(ledPin3);
lightMe(ledPin4);
swirlGate = false;
}
if (shakeGate == true) {
otherlightMe();
shakeGate = false;
}
}