Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


One Jar

Project Members: 
Alana
Jess Kline
n8agrin

Please find our write up attached and our code included below:

Arduino Code:

/**
Copyright (c) 2007 Nate Agrin; n8agrin.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

int sensorPin = 0;
int val = 0;

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

}
void loop() {
val = analogRead(sensorPin);
if (val <= 875) {
Serial.println("a");
}
else {
Serial.println("b");
}
}

Processing Code:

/*
The MIT License

Copyright (c) 2007 Nate Agrin; n8agrin.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import processing.video.*;
import processing.serial.*;
import java.io.*;
import oscP5.*;
import netP5.*;

// camera related stuff
Capture myCapture;
String cameraName;

// movie making related stuff
MovieMaker myNewMovie;
String currentNewMovie;

// movie playback stuff
Movie myMoviePlayback;
boolean playing = false;
float playbackDuration;
float playbackTime;

// serial related stuff
Serial mySerial;
boolean record = false;

// wii controller stuff
WiiController wiiController;
float[] wiiMotion = {};

// MAIN FUNCTIONS
void setup() {
// setup canvas
size(640, 480);
background(0,0,0);

// setup camera

// INSERT YOUR CAMERA MODEL NAME HERE. THIS CAN BE DISCOVERED BY UNCOMMENTING THE FOLLOWING LINE.

//println(Capture.list());

//cameraName = "IIDC FireWire Video";
//cameraName = "Logitech QuickCam Pro 3000";
myCapture = new Capture(this, width, height, cameraName, 30);

// create a serial connection
mySerial = new Serial(this, Serial.list()[0], 9600);

// wii mote
wiiController = new WiiController();
}

void draw() {
try {
checkForShaking();
if (playing && myMoviePlayback.available()) {
if (playbackDuration == myMoviePlayback.time()) {
cancelMovieIfPlaying();
background(0,0,0);
}
else {
image(myMoviePlayback, 0, 0);
}
}
captureNewMovie();
} catch (Exception e) {
println("The show must go on.");
println(e);
}
}

// EVENTS
void keyPressed() {
if (key == 'p') {
playMovie(getRandomMovie());
}
}

boolean checkForShaking() {
if (wiiMotion.length > 40) {
float maximum = max(wiiMotion);
float minimum = min(wiiMotion);
if ((maximum - minimum) > 40) playMovie(getRandomMovie());
wiiMotion = subset(wiiMotion, 0, 1);
}
else {
wiiMotion = append(wiiMotion, wiiController.roll);
}
return true;
}

void captureEvent(Capture myCapture) {
if (myCapture != null) myCapture.read();
}

void serialEvent(Serial mySerial) {
int in = mySerial.read();
if (in == 'a') record = true;
if (in == 'b') record = false;
}

void movieEvent(Movie m) {
m.read();
}

// CUSTOM FUNCTIONS
String makeMovieName() {
return (str(year()) + str(month()) + str(day()) + str(hour()) + str(minute()) + str(second()) + str(millis()) + ".mov");
}

void captureNewMovie() {
if (record) {
cancelMovieIfPlaying();
if (myNewMovie == null) {
currentNewMovie = makeMovieName();
myNewMovie = new MovieMaker(this, width, height, currentNewMovie, 20, MovieMaker.H261, MovieMaker.MEDIUM);
}
image(myCapture, 0, 0);
myNewMovie.addFrame();
}
else if (!record && myNewMovie != null) {
myNewMovie.finish();
myNewMovie = null;
println(currentNewMovie);
//playMovie(currentNewMovie);
background(0,0,0);
}
}

String getRandomMovie() {
File dir = new File("/Users/n8agrin/Documents/Processing/show_and_capture_video");
String[] files = dir.list();
String[] movieNames = {};
for(int i=0; i<files.length; i++) {
if (files[i].endsWith(".mov")) movieNames = append(movieNames, files[i]);
}
if (movieNames.length > 0) return movieNames[int(random(0,movieNames.length))];
return null;
}

void playMovie(String movieName) {
//if (!playing && movieName != null) {
playing = true;
myMoviePlayback = new Movie(this, movieName);
playbackDuration = myMoviePlayback.duration();
myMoviePlayback.play();
//}
}

void cancelMovieIfPlaying() {
if (playing) playing = false;
if (myMoviePlayback != null) {
myMoviePlayback.stop();
myMoviePlayback = null;
}
}

 


AttachmentSize
Agrin_Kline_Pechon_One_Jar.pdf213.75 KB

Powered by Drupal - Design by Artinet