Sunday, December 13, 2009

Process

The final code for my project:


IN PROCESSING
import processing.serial.*;

int x = 100;
int a= 0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;
int i=0;
int j=0;
int k=0;
int l=0;
int m=0;
int n=0;
int o=0;

Serial myPort;


int ypos1=0;
int ypos=0;
int y=0;
int yp=0;

int ypos2=0;
int y2=0;
int yp2=0;
int ypo2=0;

int ypos3=0;
int ypo3 = 0;
int yp3 = 0;
int y3= 0;
int pos3=0;

int x1=80;
int x2=180;
int x3=430;
int x4=183;
int x5=300;
int x6=500;




PFont fontA;




void setup() {
size(700,750);

println(Serial.list());

myPort= new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');

background(255);



}
void draw() {
fontA = loadFont("Square721BT-Roman-40.vlw");
textFont(fontA, 40);
fill(0);
text("How are you feeling today?",x,40);
fontA = loadFont("Square721BT-Roman-20.vlw");
textFont(fontA, 20);
fill(a);
text("Happy",80,90);
fill(b);
text("Energetic",150,90);
fill(c);
text("Distant",260,90);
fill(d);
text("Angry",355,90);
fill(e);
text("Melancholic",430,90);
fill(f);
text("Hurt",560,90);
fill(g);
text("Content",x,130);
fill(h);
text("Anxious",200,130);
fill(i);
text("Dissapointed",295,130);
fill(j);
text("Curious",440,130);
fill(k);
text("Tired",530,130);
fill(l);
text("Confused",150,170);
fill(m);
text("Amorous",260,170);
fill(n);
text("Envious",360,170);
fill(o);
text("Other",460,170);


fill(0);
rect(0,190,699,559);
fill(255);
rect(0,250,699,439);



fill(255,0,0,175);
noStroke();
rect(80,250,5,ypos1);
rect(180,250,6,ypos1);
rect(430,250,8,ypos1);

rect(81,250,5,ypos);
rect(182,250,3,ypos);
rect(433,250,6,ypos);

rect(83,250,4,y);
rect(178,250,8,y);
rect(428,250,2,y);

rect(85,250,7,yp);
rect(184,250,5,yp);
rect(425,250,8,yp);

fill(255,255,0,175);
noStroke();
rect(183,250,7,ypos2);
rect(300,250,9,ypos2);
rect(500,250,4,ypos2);

rect(182, 250, 4, ypo2);
rect(300, 250, 10, ypo2);
rect(499, 250, 5, ypo2);

rect(183, 250, 5, yp2);
rect(299, 250, 3, yp2);
rect(501, 250, 8, yp2);

rect(178, 250, 6, y2);
rect(303, 250, 11, y2);
rect(504, 250, 4, y2);

fill(0,0,255,175);
noStroke();
rect(301, 250, 5, ypos3);
rect(431, 250, 12, ypos3);
rect(600, 250, 7, ypos3);

rect(302, 250, 6, yp3);
rect(429, 250, 3, yp3);
rect(601, 250, 9, yp3);

rect(299, 250, 8, y3);
rect(432, 250, 5, y3);
rect(599, 250, 4, y3);

rect(298, 250, 4, ypo3);
rect(433, 250, 8, ypo3);
rect(604, 250, 6, ypo3);

rect(301, 250, 8, pos3);
rect(302, 250, 10, pos3);
rect(299, 250, 4, pos3);



fill(0);
rect(0,709,699,40);








emotion();

}

void emotion () {
if (mouseX>70&&mouseX<130&&mouseY<=100&&mouseY>80&&mousePressed){
a = 100;
ypos2=ypos2+3;
myPort.write(98);

}else {
a=0;
myPort.write(65);
}
if(mouseX> 140&&mouseX<245&&mouseY<=100&&mouseY>80&&mousePressed){
b=100;
ypos2+=3;
myPort.write(98);
ypos1+=3;
myPort.write(97);
}else {
b=0;
myPort.write(65);}
if(mouseX>255&&mouseX<340&&mouseY<=100&&mouseY>80&&mousePressed){
c=100;
ypos3+=3;
myPort.write(99);
if(ypos3 >= 100){
ypo2+=3;
myPort.write(98);}
}else{
c=0;
myPort.write(65);
}if(mouseX>350&&mouseX<415&&mouseY<=100&&mouseY>80&&mousePressed){
d=100;
ypos+=3;
myPort.write(97);

}else{
d=0;
myPort.write(65);
}if(mouseX>430&&mouseX<540&&mouseY<=100&&mouseY>80&&mousePressed){
e=100;
yp3+=3;
myPort.write(99);


}else{
e=0;
myPort.write(65);}
if(mouseX>555&&mouseX<620&&mouseY<=100&&mouseY>80&&mousePressed){
f=100;
y3+=3;
myPort.write(99);
if(y3>=30){
y+=3;
myPort.write(97);}

}else{
f=0;
myPort.write(65);
}if(mouseX>100&&mouseX<180&&mouseY<=140&&mouseY>120&&mousePressed){
g=100;
ypos2+=3;
myPort.write(98);
if(ypos2 >=20){
yp+=3;
myPort.write(97);
yp3+=3;
myPort.write(99);}
}
else{
g=0;
myPort.write(65);}
if(mouseX>200&&mouseX<275&&mouseY<=140&&mouseY>120&&mousePressed){
h=100;
yp2+=3;
myPort.write(98);
if(yp2 >39){
ypos3+=3;
myPort.write(99);}
if(ypos3>50){
yp+=3;
myPort.write(97);}
}else{
h=0;
myPort.write(65);}
if(mouseX>295&&mouseX<420&&mouseY<=140&&mouseY>120&&mousePressed){
i=100;
ypo3+=3;
myPort.write(99);
if(ypo3>50){
y+=3;
myPort.write(97);}
}else{
i=0;
myPort.write(65);
}if(mouseX>440&&mouseX<510&&mouseY<=140&&mouseY>120&&mousePressed){
j=100;
y2+=3;
myPort.write(98);
if(y2>10){
yp3+=3;
myPort.write(99);
ypos+=3;
myPort.write(97);
}
}else{
j=0;
myPort.write(65);
}if(mouseX>530&&mouseX<630&&mouseY<=140&&mouseY>120&&mousePressed){
k=100;
pos3+=3;
myPort.write(99);
if(pos3>=40){
pos3=40;
myPort.write(65);}
}else{
k=0;
}if(mouseX>150&&mouseX<240&&mouseY<=180&&mouseY>160&&mousePressed){
l=100;
y3+=3;
myPort.write(99);
y+=3;
myPort.write(97);
if(y3>190){
y2+=3;
myPort.write(98);}
}else{
l=0;
myPort.write(65);
}if(mouseX>260&&mouseX<340&&mouseY<=180&&mouseY>160&&mousePressed){
m=100;
ypos+=3;
myPort.write(97);
if(ypos>100){
ypos2+=3;
myPort.write(98);}

}else{
m=0;
myPort.write(65);
}if(mouseX>360&&mouseX<440&&mouseY<=180&&mouseY>160&&mousePressed){
n=100;
yp3+=3;
myPort.write(99);
ypo2+=3;
myPort.write(98);
}else{
n=0;
myPort.write(65);
}if(mouseX>460&&mouseX<560&&mouseY<=180&&mouseY>160&&mousePressed){
o=100;
ypos1+=3;
myPort.write(97);
ypos2+=3;
myPort.write(98);
ypos3+=3;
myPort.write(99);
}else{
o=0;
myPort.write(65);}}



IN ARDUINO

int yellow = 13;
int red = 12;
int blue = 11;

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("test!");


pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);}
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(blue, LOW);



void loop() {
char c;

if (Serial.available()) {
c = Serial.read();
Serial.println(c, BYTE);
if (c == 'a') {
digitalWrite(red,HIGH);
}
else if (c == 'b') {
digitalWrite(yellow, HIGH);
}
else if (c == 'c') {
digitalWrite(blue, HIGH);
}

else if(c=='A') {
digitalWrite(red,LOW);
digitalWrite(yellow,LOW);
digitalWrite(blue, LOW);}
return;
}}



The only issues I had with getting my project to work was with trying to figure out the schematic of circuit and powering the solenoids with enough power to hold their valves open. I set up the circuit based on this schematic:




Every site I went to had pretty much the same diagram... but my solenoid wouldn't respond to the output signal from the pin, they would just stay open. I realized that the transistors i was using weren't for a high enough voltage to support the 12V current. This was a simply fix. Besides the leaking, and the transistors, I really didn't run into any problems.

No comments:

Post a Comment