Assignment Week #11

For this week’s project, we needed to find a way to combine both Arduino and Processing. I ended up basing the code off of the art project that we did a few weeks ago. I tried to think of some ways to use different things other than the knobs such as Aaron suggested, and ended up using two controllers: a knob and a pressure sensor.

I just thought it would be interesting to work with both these sensors in relation to one another and see the power of each in relation to affecting the processing drawing.

Codes:

Arduino:

void setup() {
Serial.begin(9600);
}

void loop() {
if(Serial.available()>0){
char inByte=Serial.read();
int sensor = analogRead(A0);
delay(0);
int sensor2 = analogRead(A1);
delay(0);
Serial.print(sensor);
Serial.print(‘,’);
Serial.println(sensor2);
}
}

Processing:

import processing.serial.*;
Serial myPort;
int xPos=0;
int yPos=0;

Shape shape1;
Shape shape2;
Shape shape3;
Shape shape4;
Shape shape5;
Shape shape6;
Shape shape7;
Shape shape8;

int x1= mouseX;
int y1 = mouseY;
color red = color(255, 0, 0, 20);
color green = color(0, 255, 0, 30);
color blue = color(0, 0, 255, 10);

void setup(){
size(960,720);
printArray(Serial.list());
String portname=Serial.list()[3];
println(portname);
myPort = new Serial(this,portname,9600);
myPort.clear();
myPort.bufferUntil(‘\n’);
smooth();
colorMode(HSB);
shape1 = new Shape(xPos, yPos, 250, 150, 250, 250, 100, 100);
shape2 = new Shape(xPos, yPos, 150, 250, 250, 250, 400, 200);
shape3 = new Shape(xPos, yPos, 400, 250, 250, 250, 100, 400);
shape4 = new Shape(xPos, yPos, 250, 400, 250, 250, 50, 290);

}
void draw(){
background(100, 105, 100);
shape1.display();
shape2.display();
shape3.display();
shape4.display();
noStroke();
}
void serialEvent(Serial myPort){
String s=myPort.readStringUntil(‘\n’);
s=trim(s);
if (s!=null){
int values[]=int(split(s,’,’));
if (values.length==2){
xPos=(int)map(values[0],0,1023,0, width);
yPos=(int)map(values[1],0,1023,0, height);
}
}
println(xPos);
myPort.write(‘0’);
}

Class Processing:

class Shape{

//Variables
int x1, y1, x2, y2, x3, y3, x4, y4;

//The Constuctor
Shape(int px1, int py1, int px2, int py2, int px3, int py3, int px4, int py4){
x1 = px1;
y1 = py1;
x2 = px2;
y2 = py2;
x3 = px3;
y3 = py3;
x4 = px4;
y4 = py4;
}
//Functions

void display(){

x1 = xPos; //use xPos and yPos
y1 = yPos;
quad(x1, y1, x2, y2, x3, y3, x4, y4);

}

}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *