Final Project Documentation_ Interactive Chair

After my presentation, I made some change about my chair. Instead of making three chairs, I decided to focus on one. I hided all the sensors and arduino below so it can be put in the public space.
Also, I changed the function. The pressure sensors cannot read exactly the weight is so I designed one of them for creating balls, another for controlling color, and the other for controlling height.

ImageImage

int analogPin1 = 0;
int analogPin2 = 1;
int analogPin3 = 2;
int inByte = 0;
int buzzerPin = 8;
int upSound[] = {100, 200, 300, 400, 500, 600, 700, 800};

float xPos = 0;

void setup(){
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
establishContact(); while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}

void loop(){
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
Serial.write(analogRead(analogPin1));
Serial.write(analogRead(analogPin2));
Serial.write(analogRead(analogPin3));

if (inByte == ‘Y’) {
for(int i = 0; i<= 7; i++){
tone(buzzerPin, upSound[i]);
delay(200);

}
noTone(buzzerPin);
}
if (inByte == ‘W’) {
tone(buzzerPin, 700);
delay(100);
noTone(buzzerPin);
}
if (inByte == ‘R’) {
tone(buzzerPin, 900);
delay(100);
noTone(buzzerPin);
}

delay(100); //change the delay time here
}
}

void establishContact() {
while (Serial.available() <= 0) {
Serial.print(‘A’); // send a capital A
delay(300);
}
}

Processing

import processing.serial.*;
Serial myPort; // The serial port

import ddf.minim.*;
Minim minim;
AudioPlayer song1;
AudioPlayer song2;
AudioPlayer song3;

int[] serialInArray = new int[3]; // Where we’ll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int Sensor1 = 0;
int Sensor2 = 0;
int Sensor3 = 0; // Starting position of the ball
int numBalls;
boolean firstContact = false; // Whether we’ve heard from the microcontroller
boolean play = false;
Ball []ball;

void setup() {
size(displayWidth, displayHeight);
noStroke(); // No border on the next thing drawn

minim = new Minim(this);
song1 = minim.loadFile(“4.mp3”);
song2 = minim.loadFile(“5.mp3”);
song3 = minim.loadFile(“6.mp3”);

numBalls = 0;
ball = new Ball[10000];

for(int i=0; i< 10000; i++){
ball[i] = new Ball();
}

// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
String portName = Serial.list()[4];
myPort = new Serial(this, portName, 9600);

}

void draw() {
background(255);
//Sensor1
if(Sensor1 < 50 && Sensor1 > 1){
ball[numBalls] = new Ball();

if(Sensor2 < 150 && Sensor2 >= 120){
ball[numBalls].ballColor = color(random(255), 250, random(150), 180);
}
else if(Sensor2 < 200 && Sensor2 >= 150){
ball[numBalls].ballColor = color(random(255), random(200), 250, 180);
}

if(Sensor3 < 50 && Sensor3 >= 20){
ball[numBalls].vY = random(0,50);
}
else if(Sensor3 < 80 && Sensor3 >= 50){
ball[numBalls].vY = random(0,100);
}
myPort.write(‘Y’);
song1.play();
play = true;
if(play == true){
song1.rewind();
song1.play();
}

numBalls++;
play = false;
}
else if(Sensor1 < 100 && Sensor1 >= 50){
for(int i=0; i<3; i++){
ball[numBalls] = new Ball();
ball[numBalls].bSize = 45;

if(Sensor2 < 150 && Sensor2 >= 120){
ball[numBalls].ballColor = color(random(255), 250, random(150), 180);
}
else if(Sensor2 < 200 && Sensor2 >= 150){
ball[numBalls].ballColor = color(random(255), random(200), 250, 180);
}
if(Sensor3 < 50 && Sensor3 >= 20){
ball[numBalls].vY = random(0,50);
}
else if(Sensor3 < 80 && Sensor3 >= 50){
ball[numBalls].vY = random(0,100);
}
myPort.write(‘W’);
song2.play();
play = true;
if(play == true){
song2.rewind();
song2.play();
}

numBalls++;
play = false;
}
}
else if(Sensor1 < 200 && Sensor1 >= 100){
for(int i=0; i<8; i++){
ball[numBalls] = new Ball();
ball[numBalls].bSize = 65;

if(Sensor2 < 150 && Sensor2 >= 120){
ball[numBalls].ballColor = color(random(255), 250, random(150), 180);
}
else if(Sensor2 < 200 && Sensor2 >= 150){
ball[numBalls].ballColor = color(random(255), random(200), 250, 180);
}
if(Sensor3 < 50 && Sensor3 >= 20){
ball[numBalls].vY = random(0,50);
}
else if(Sensor3 < 80 && Sensor3 >= 50){
ball[numBalls].vY = random(0,100);
}
myPort.write(‘R’);
song3.play();
play = true;
if(play == true){
song3.rewind();
song3.play();
}

numBalls++;
play = false;
}

}

for(int i=0; i < numBalls; i++){
ball[i].drawBall();
ball[i].movement();
}

}

void stop(){
song1.close();
song3.close();
minim.stop();
super.stop();
}

void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it’s an A,
// clear the serial buffer and note that you’ve
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == ‘A’) {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you’ve had first contact from the microcontroller
myPort.write(‘A’); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;

// If we have 3 bytes:
if (serialCount > 2 ) {
Sensor1 = serialInArray[0];
Sensor2 = serialInArray[1];
Sensor3 = serialInArray[2];

// print the values (for debugging purposes only):
println( Sensor1+ “\t” + Sensor2 + “\t” + Sensor3);

// Send a capital A to request new sensor readings:
myPort.write(‘A’);
// Reset serialCount:
serialCount = 0;
}
}
}

class Ball{

float bSize = 25;
float r = bSize/2;
float endPosX;
float endPosY = displayHeight-(bSize/2);
float ballPosX;
float ballPosY;
float vY =.1;
float gravity = .98;
float weight = .09;
float vX;
float friction = .9;
color ballColor;

public Ball(){
ballPosX = displayWidth/2;
ballPosY = displayHeight;
ballColor = color(255, random(230), random(150), 180);
vX = random(-20,20);
vY = random(0,30);
}

public void drawBall(){
noStroke();
fill(ballColor);
ellipse(ballPosX,ballPosY,bSize,bSize);
}

public void movement(){

// Up/Down Motion
if((ballPosY < endPosY) && (vY > 0)){
vY += gravity; //going down!
} else if((ballPosY > endPosY) && (vY > 0)) {
vY = -vY; //flip to up
} else if((vY <= 0) && (ballPosY > r)) {
vY += gravity; // going up
vY = vY*(1-weight);
} else if(ballPosY <= r) {
vY = -vY; // flip to down
}

ballPosY += vY;
ballPosX += vX;
}
}

Leave a comment

Filed under Uncategorized

Leave a comment