Friday, December 15, 2006

Completion

The project works! I had made a mistake in my code. The for loop was written incorrectly but that is fixed. Pictures and video will be coming soon.

Tuesday, December 12, 2006

Final Program

//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;
}
}

Monday, December 04, 2006

Gesture Recognition

I think the code would look something like this. oldMotion I guess would be manually inputed in the Arduino code. newMotion would need a "for loop" to store the data. Would it be better to create two arrays, one for X and one for Y? Will the 8-bit chip be able to handle all this? If swirlGate became true the lights would swirl. The +/- 5 is arbitrary. This does not compensate for speed.



int testVal = 0;
int newMotion[100];
int oldMotion[100];
boolean swirlGate = false;

void recognizeSwirl(){
for(int z = 0; z > 100; z++){
//check new array to old
testVal = abs(newMotion[z] - oldMotion[z]);
if(testVal<5) swirlGate = true;
else swirlGate = false;
}
}

Questions

Questions:

Wiring: I have never soldered more than one thing to a transistor, how do I solder several lights?

Prototype Board: How do I cut it? It is much larger than my cylinder.

Programming: I can get it to figure out which side is up and I know generally how to create a gesture program. Do I have to manually put in the array its checking against? Also how do I compensate for speed?

Playing around


All things have been received. I now have the prox sensor and two super bright LEDs. I need to wire the LEDs into a circular pattern so I had to buy prototype board. I could only find it in Chinatown since Radioshack was out of it. I have yet to solder anything because I have some questions on wiring the board. For now I have the arduino figuring out which side is up and lighting a LED. I need to work on the behavior and gesture recognition but I have questions about how to program this. I am posting a picture of the breadboard and the arduino code (it works!!). The white wires off screen are going to the accelerometer.



//Values for the LEDs each LED must have two pins
//test
int ledPin0 = 13;
//top
int ledPin1 = 12;
int ledPin2 = 11;
//right
int ledPin3 = 10;
int ledPin4 = 9;
//left
int ledPin5 = 8;
int ledPin6 = 7;
//bottom
int ledPin7 = 6;
int ledPin8 = 5;

//Sensor Pins
//Accelerometer Analog Input
int sensorPinX = 0;
int sensorPinY = 1;
//QPROX sensor
int sensorPinP = 2;

//Values for sensosrs
int valX = 0;
int valY = 0;

void setup () {
//Declaring input and output
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(sensorPinX, INPUT);
pinMode(sensorPinY, INPUT);
pinMode(sensorPinP, INPUT);
//Setting up serial
Serial.begin(9600);
}

//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, int l2) {
//PWM ramp up
for (int i=1; i<400; i++) {
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delayMicroseconds(i);
digitalWrite(l1, LOW);
digitalWrite(l2, LOW);
delayMicroseconds(i);
delay(5);
}
//PWM ramp down
for (int i=399; i>0; i--) {
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delayMicroseconds(i);
digitalWrite(l1, LOW);
digitalWrite(l2, LOW);
delayMicroseconds(i);
delay(5);
}
}

void loop(){
//Reading Accelerometer
valX = analogRead(sensorPinX);
valY = analogRead(sensorPinY);
//Printing data for programming reasons
Serial.print("X: ");
Serial.println(valX, DEC);
Serial.print("Y: ");
Serial.println(valY, DEC);
//the following test the accelerometer to see which end it up and it will currently light that LED
//top test
if (valX>500 && valX<515 && valY>435 && valY<510) {
lightMe(ledPin0,ledPin0);
}
else {
digitalWrite(ledPin0,LOW);
}

//right test
if (valX>410 && valX<459 && valY>500 && valY<540) {
lightMe(ledPin1,ledPin2);
}
else {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}
//bottom test
if (valX>515 && valX<525 && valY>520 && valY<600) {
lightMe(ledPin3,ledPin4);
}
else {
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
}

//left test
if (valX>515 && valX<600 && valY>520 && valY<500) {
lightMe(ledPin5,ledPin6);
}
else {
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
}

}