Monday, December 04, 2006

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

}

0 Comments:

Post a Comment

<< Home