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!


lab4

Project Members: 
Wenhua Shi
using pressure / photo sensors to control processing ball paint.


Processing Code:

/*
* Arduino Ball Paint
* (Arduino Ball, modified)
* ----------------------
*
* Draw balls randomly on the screen, size controlled by a device
* on a serial port.  Press space bar to clear screen, or any
* other key to generate fixed-size random balls.
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A4001nQ5"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
void setup() {
  size(300,300);
  frameRate(10);
  smooth();
  background(80,80,80);
  noStroke();
  port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
  if(key == ' ') {
    background(40,40,40);  // erase screen
  }
  else {
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball(x,y, 50);
  }
}
// draw balls
void drawball(int x, int y, int r) {
  for (int i=0; i<100; i++ ) {
    fill(255-i,i,240);
    ellipse(x,y,r,r);
  }

}
// called whenever serial data arrives
void serialEvent(Serial p) {
  int c = port.read();
  if (c != lf && c != cr) {
    buf += char(c);
  }
  if (c == lf) {
    int val = int(buf);
    println("val="+val);
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball(x,y,val);
    buf = "";
    background(40,40,40);  // erase screen
  }
}

AttachmentSize
noname-1.jpeg65.02 KB

Powered by Drupal - Design by Artinet