Monday, December 17, 2007

code for final

Version 11:

// ICM Final boxes + scrolling images test
// Buggy version: once I implemented the serial boxes, my text boxes shift up and to the left.
// 12.11.07


import processing.serial.*;
Serial myPort;

int imageIndex = 0; // Initial image to displayed is the first
PImage [] images = new PImage [6]; // because we have 6 images that we want to scroll through for now. Keep in mind we're not going to know for sure
// how many images will come from the camera each day, and this should not be hardcoded.
long changeInterval = 2000; // milliseconds, that is.
long lastChange = 0;
// PImage gpsPic; // to be coded in later when i have a .jpg pic for my GPS placeholder

//----------------------------------- heart monitor setup -------------//
Box [] boxes;
int serialValue = 0;
int yHMB;
int currentHMB;


//----------------------------------- typing text for comments box ----//
PFont f; // for typing text function
String typing = "";
String saved = "";
String saved2 = "";
String saved3 = "";
String saved4 = "";
String saved5 = "";

// ---------------------------------- text boxes below ----------------//

TextBox vitalsBox; // upper left hand box
TextBox gpsBox; // lower left hand box
TextBox commentBox; // far right box
TextBox heartMonitorBox; // small box nested inside vitals box




void setup ()
{

size(790,550);


// -------------------------------------- text in text boxes ---------------//
f = loadFont("HelveticaNeue-15.vlw"); // typing font for comments box

vitalsBox = new TextBox(75,74,134,122);
heartMonitorBox = new TextBox(75,168,140,315); // (int _xposTB, int _yposTB, int _width, int _height)
gpsBox = new TextBox(75,420,140,175); // (xpos,ypos,height of box)
commentBox = new TextBox(717,260,140,500);



// -------------------------------------background images code ------------//

String [] pictures = {
"awesomeTV2.jpg","dad.jpg","MIDIbox.jpg","MiXem1.jpg","MiXem2.jpg","09greenspace.jpg" }; // these images work! resized to normal file size.
for (int i = 0; i < pictures.length; i++) {
if (frameCount % 60 == 0) { // Hulya's code -- if frameRate....
images[i] = loadImage(pictures[i]); // for every instance of "images," load the corresponding instance of the string "pictures"
}
}

//gpsPic = loadImage("Mississippi.tif"); // processing can't display .tif images!!! replace w/ .jpg, .gif, .tga, .png
//image(gpsPic,0,0);




// ------------------------------------ heart monitor + serial ------------//

print(Serial.list()); // just what you do with Serial. you list your ports.
myPort = new Serial (this, Serial.list()[0], 9600);
boxes = new Box [150];

for (int j = 0; j < boxes.length; j++) {
boxes[j] = new Box ((j),yHMB,1,1,-2, color(yHMB,0,0,50)); // color seemingly does nothing here.
}
}



void draw()
{
background(0);

// --------------------------------- setting the delay on the background pics ------//

frameRate(30);
image(images[imageIndex],150,10); // displaying the images, at the following coordinates.

if (lastChange + changeInterval < millis()) {
imageIndex = (imageIndex + 1) % images.length;
lastChange = millis();
}


// ------------------------------------- text boxes, etc. ---------------------------//

heartMonitorBox.displayBox();
vitalsBox.displayBox(); // shouldn't I be able to build the boxes with arguments rather than a constructor?
gpsBox.displayBox();
commentBox.displayBox();


// ------------------------------------------ typing text for comments box-----------//
int indent = 650;
textFont(f);
fill(255);
text(typing,indent,90); // typing text, x value, y value
text(saved,indent,130); // saved text, x value, y value
text(saved2,indent,170);
text(saved3,indent,210);
text(saved4,indent,250);
text(saved5,indent,290);


// ------------------------------------------- heart monitor Serial input ------------//

for (int j = 0; j < boxes.length; j++) {
boxes[j].move();
boxes[j].display();
}

boxes[currentHMB].setY(yHMB);
currentHMB = (currentHMB + 1) % boxes.length;

fill(255);
text("David Young", 10,30);
text("Test: Cardiogram",10,45);
text("Date: December 11",10,60);
text("Pulse: " + serialValue,10,85);

text("GPS", 10,350);


}



void serialEvent(Serial myPort) {
serialValue = myPort.read();
println(serialValue);

if (serialValue > 0) {
yHMB = (height-240) - serialValue; // adjust this (30) to proper height of box. Try to constrain to box
}
else {
yHMB = height-240;
}
}


//-------------------------------------------- typing text for comments box----------//


void keyPressed()
{
if (key == '\n') {
saved5 = saved4;
saved4 = saved3;
saved3 = saved2;
saved2 = saved;
saved = typing;
typing = "";
// Otherwise, concatenate the String with what the user pressed on the keyboard.

}
else {
typing = typing + key;
}
}



// ------------------------ Text boxes ------------------------


class TextBox // creating a class for my boxes
{


int xposTB; // initialing the variables of each of the boxes.
int yposTB;
int boxheight;
int boxwidth;

TextBox(int _xposTB, int _yposTB, int _width, int _height) { // my constructor w/ 3 variables
xposTB = _xposTB; // the x coord
yposTB = _yposTB; // the y coord
boxwidth = _width;
boxheight = _height; // the height
}


void displayBox() // making a function called displayBox().
{
stroke(255);
fill(255,255,255,50);
rect(xposTB,yposTB,boxwidth,boxheight); // based on my constructor values. This is top left corner placement (xpos,ypos), width of box (boxwidth), and height (boxheight).
}
}



// -------------------------- heart monitor -----------------------



class Box
{

float xpos;
float ypos;
float xwidth;
float ywidth;

float xspeed;

color c;


Box(float tempXpos, float tempYpos, float tempXwidth, float tempYwidth, float tempXspeed, color tempC) {
xpos = tempXpos;
ypos = tempYpos;
xwidth = tempXwidth;
ywidth = tempYwidth;

xspeed = tempXspeed;

c = tempC;

}

void display() {
rectMode(CENTER); // SHIT!!!! RECT MODE CENTER!!!!! screwed up my text boxes!!!!!
stroke(200);
fill(c,0,0,200);
rect(xpos,ypos,xwidth,ywidth);

}

void move() {


xpos = xpos + xspeed; // position of each box is determined by it's xpos + xspeed
//xpos = constrain(xpos,20,width-640); // why doesn't this work? ah, because i don't regenerate the boxes. were they looped, they would.
ypos = ypos + 5; // by adding ypos + 1, this ensures that the boxes gradually fall back to the bottom
ypos = constrain(ypos,0,height-240);
if (xpos <= 0) {
xpos = width-650;
ypos = height-240;
}
}

void setY(float tempY) { // drumming up a setY function, with an argument of tempY
ypos = yHMB; // setting ypos to equal y
}

//void setYback(float tempY) {
// ypos = height - 30;
//}

}




... and finally, here's the code for Arduino


// ICM Final data

int analog0 = 0;
int heartMonitor;

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


void loop() {

heartMonitor = (analogRead(analog0)/4);

Serial.print(heartMonitor, BYTE); // important to be BYTE so Processing reads correctly.

}

Wednesday, December 12, 2007

last minute shameless post for class presentation

ok, well, here she is. An early prototype screen grab of what I imagine my interface to look like for the Mississippi River Project (the name of which, by the way, needs to change... it sounds like a code name for a bomb or something). Take a look:








What works:
-I like the comments bar in the far right, that looks good to me
-pictures scrolling nicely with timer (2000ms, or 2 seconds each)

What doesn't work is:
-no GPS implementation yet
-ugliest code you've ever seen
-basic text/type functionality (no backspace or constraints yet)
-heart monitor not quite sorted out.


Also, I've been contacted by the operator of this site: http://www.sourcetosea.net/

He and his wife canoed the Mississippi two years ago and have a book coming out about their trip. Their documentation looks fantastic, and I'd love to get some tips and such from him.

I've also come across some good advice from the Waymarkr folks. They know their stuff about series 60 phones, especially with regards to battery/signal limitations.

Friday, November 16, 2007

camera working!














Ok so i got the Xacti working. It's very basic, but using the Xacti VPC-CG 65 (that is, the NON-high def one) I can hook it up to processing wiht the following code:


import processing.video.*;



Capture video;

void setup()
{
size(320,240);
video = new Capture (this,320,240,15);
}

void draw()
{
if (video.available()) {
video.read();
}

image(video,0,0);

}



However, I am running into some problems.
1) keeping the camera on. Processing (smartly) defaults to the built in iSight, so when the Xacti doesn't "record" anything, it shuts off after a while. I'd spend more time looking into this, but since my dad prob won't have this particular camera on him, I'm not gonna worry about it. It'll be an issue with the phone and it's camera, however, because I'm sure that that sucks battery like crazy.

2) having trouble getting it to work with iChat as well. Again, not much of an issue for the upshot of this project, but iChat would make a nice testing ground to see if any of these cameras work.


Have yet to get in touch with the Waymarkr gang, but that's the next step I think. Then graphics.

Tuesday, November 6, 2007

Final Exam project proposal

Ok, so two weeks ago, I presented the beginnings of a crude heart monitor. It's really not a heart monitor at all; rather, it's merely a simple force sensing resistor hooked up into my arduino microprocessor with a graphical interface into Processing. To say it that way makes it sound really complicated, but it's actually not.

Being a force sensing resistor, it registers the amount of force you apply and animates that information, so you really have to replicate a heartbeat by pinching it. However, it does look pretty cool, if not a bit basic. Working on getting a screen shot for you guys soon...

Anyways, now that I've got serial communication between the Arduino microcontroller and the Processing environment, I'm in good shape for my final. My idea for the final is to certainly not have this entire project done. In fact, Shiffman (my ICM prof) suggested that this could even be a worthy thesis, or something for longer term. I think that's all well and good, but dad canoes next fall, and I'd like to have this done by then.

For now, however, I'm going to content myself with creating a much prettier interface that will show "live" video, coupled with serial input that will display this crude heart monitor, GPS coordinates, and a texting feature. Here's a sketch of my idea:



Ok, so it's pretty crude, but you get the idea I hope. I'm thinking the main projection will be this "live video" feed, but since live video would be completely struggling (esp in areas of low cell coverage) I'm gonna use something similar to the very cool WayMarkr, which was developed here at ITP. It basically takes a cell phone camera to take pictures every few minutes and beams those images directly to a website. Perfect!

Then, off to the sides, I'll have text boxes that will print vitals feedback (upper left hand side of the screen), GPS map and data feedback (lower left hand side), and then text messages to some sort of apparatus (on the right hand side of screen). These will be stylishly imaged in some sort of transparent box on top of the actual photo.

I figure this to be a dry run to see how the information passes to a computer interface, like Processing. For the actual implementation of the project, I'd like to be able to use the same code I've written here, but pass it through a cell phone rather than my computer. Shiffman suggested the very nice Nokia N95, which conveniently contains a GPS unit AND a very excellent camera. Check it:




Anyways, this project is a LONG way from being finished, but hopefully executing this code in Processing will be good practice to see if it works in the long run.

Wednesday, October 24, 2007

Intro

Hi all.... and welcome to my Mississippi River blog. It actually won't have anything to do with the Mississippi River until next year; right now, I'm just in the planning stages of building something to be used on the Mississippi River.

My dad, pictured below, is retiring next year and recently got the idea to paddle the mississippi river in a canoe. He's a pretty avid canoe-er, or at least was when he was younger, and now that he's retiring I think he's gonna get back into it. Either way, it's a meaningful trip for him, all the way down the Mississippi, that is, because he was born and raised in Baton Rouge, LA but spent a lot of time in Minneapolis, MN. The Mississippi starts in MN and spits out into the Gulf of Mexico in Louisiana, for you geography whizzes out there.

Note the beer, which he'll prob have to take it easy on for his training.



Anyways, I'm gonna try to help him out. Ideally, I'd like to build something that that would 1) document his progress, and 2) aid in our communication with him. I'd like for our family to be able to jump onto a computer at any time, type otu a message to him, and have it delivered to a wearable screen of some sort. So we could send out messages of encouragement and such... also, it'd be really cool to see how he's doing. Where he's at, how he's feeling, how much progress he's made, even what he LOOKS like as he's paddling down the hundreds of miles of Mississippi river. Then, to have his journey documented with some sort of camera would be ideal as well -- in fact, if any part of this comes together, it's the documentation piece that I think he'll like the most.

So far, I can think of about a million things that I need to give more thought to before putting this project together. How to wirelessly communicate in places that might not have wireless access, for example. But for now, I've just focused on creating a vitals monitor for him through the Processing environment. More on that code and it's functionality later.