Category Archives: Your work

Final Project – Big Brother Time!

Had a great time in the class. It was great meeting each of you and getting the change to learn something new!

My project uses a FSR to manage the color of a box on a grid that correspond to the day and hour of the week. There is a check periodically through each hour, and when there is pressure when checked, it moves the color of the box from white to black gradually. Scott got me going on the hour and day portion which was really helpful.

IMG_0096

 

Processing code:

import processing.serial.*; // import the serial library
import java.util.Date; // import the java date library

Serial mySerial; // an instance of the serial class

int thisBox = 255; // the variable that describes the box color

int prevHour; // a variable to hold the previous hour
// use this to check for a change in the hour
// and reset the color variable

int xPos =0; // a variable for the xPosition of a box (if you want to go that route)
int yPos =0; // a variable for the yPosition of a box (if you want to go that route)

void setup() {
size(700, 600); // a larger window so that it’s more legible
println(Serial.list()); // list our serial ports

String portName = Serial.list()[1]; // get the port name
// open the serial port at 9600 baud
mySerial = new Serial(this, portName, 9600);
// when we receive anewline char, trigger the serialEvent fxn
mySerial.readStringUntil(‘\n’);

// white background
background(255);

// draw a grid in black
for (int i = 0; i<700; i=i+100) {
for (int j = 0; j<1200; j=j+25) { // CD- back to 800
rect(i, j, 100, 25);
}
}
}

void draw() {
// variables to hold the hour and day of the week
int hour = hour(); /// 24 hour clock 9 10 11 12 13 14 15 16 17 18 etc….
int day=new Date().getDay(); //0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturda

// if the hour has changed
if (hour !=prevHour) {
thisBox=255; // make the new fill color white
prevHour=hour; // set the previous hour to this hour
}

fill(thisBox); // fill color for the box you’re currently writing to

// you can set this up to change a variable for the box x,y position
// so that if day == 1, xPos = 0. if day==2, xPos=100 (etc).
// and for the hours if hour ==9, yPos=0. if hour=10, yPos =100 (etc.)

if (hour == 1) { // if 9am CD-back to 9
yPos =0;
} else if (hour==2) { // if 10 am
yPos=25;
} else if (hour==3) { // if 10 am
yPos=50;
} else if (hour==4) { // if 10 am
yPos=75;
} else if (hour==5) { // if 10 am
yPos=100;
} else if (hour==6) { // if 10 am
yPos=125;
} else if (hour==7) { // if 10 am
yPos=150;
} else if (hour==8) { // if 10 am
yPos=175;
} else if (hour==9) { // if 10 am
yPos=200;
} else if (hour==10) { // if 10 am
yPos=225;
} else if (hour==11) { // if 10 am
yPos=250;
} else if (hour==12) { // if 10 am
yPos=275;
} else if (hour==13) { // if 10 am
yPos=300;
} else if (hour==14) { // if 10 am
yPos=325;
} else if (hour==15) { // if 10 am
yPos=350;
} else if (hour==16) { // if 10 am
yPos=375;
} else if (hour==17) { // if 10 am
yPos=400;
} else if (hour==18) { // if 10 am
yPos=425;
} else if (hour==19) { // if 10 am
yPos=450;
} else if (hour==20) { // if 10 am
yPos=475;
} else if (hour==21) { // if 10 am
yPos=500;
} else if (hour==22) { // if 10 am
yPos=525;
} else if (hour==23) { // if 10 am
yPos=550;
} else if (hour == 0) { // if 9am CD-back to 9
yPos =575;
}

if (day == 1) { // if Monday
xPos =0;
} else if (day ==2) { // if Tuesday
xPos =100;
} else if (day ==3) { // if Tuesday
xPos =200;
} else if (day ==4) { // if Tuesday
xPos =300;
} else if (day ==5) { // if Tuesday
xPos =400;
} else if (day ==6) { // if Tuesday
xPos =500;
} else if (day ==0) { // if Tuesday
xPos =600;
} /// continue for the other days of the week thru Fri

// draw the box
rect(xPos, yPos, 100, 25);
}
// serialEvent only fires when a message is received from the Arduino
// in this case it’s only once a minute (because that’s how often the
// Arduino fires
void serialEvent(Serial port) {
if (port == null) return; // make sure there’s information

String inString = port.readStringUntil(‘\n’); // read until the newline character

if (inString != null) { // as long as there’s an actual word in there
inString = trim(inString); // trim off any whitespace:
//}
String check = “working”;
println(inString);
if (inString.equals(check)) { // if the arduino sent working”
println(“here”);
if(thisBox>5)
thisBox = thisBox-25; // make the color for the box a little darker
// 4*60=240, which would be pretty close to black if someone is in the chair the full hour
} else {
// nothing to do if someone’s not working
}
}
}

 

Arduino code

int fsrVal; // variable to hold the senspr value

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // start serial communication
}

void loop() {
// put your main code here, to run repeatedly:
fsrVal = analogRead(A0); // read the sensor, save in variable

if (fsrVal < 999) { // if the sensor value is less than 999
Serial.println(“working”); // send a “working” message
} else if (fsrVal >= 1000) { // if it’s greater or equal to 1000
Serial.println(“notWorking”); // send the “not working” message
}
delay(600); // wait one minute before the next read
}

 

Prismatic Box