Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Dano Wed

Intro to Physical Computing (Fall 2009)

syllabus - Labs

Laptops

Laptops are very useful tools, but they are also very effective instruments of distraction. Everyone benefits if we all pay attention. I'll do my best to keep the class interesting, I hope you'll join me in this pursuit. You are welcome to use your laptop in class when I am speaking, or when it is relevant to the classwork being presented. However, during discussions and when your fellow students are talking, please be respectful of everyone's time and close the lid. If necessary, I'll remind of this, but even better would be if everyone does so naturally.

Links

Syllabus
Lab Assignments
Tom Igoe's Physical Computing Site
Tom Igoe's Code and Resources Blog
ITP Sensor Workshop Wiki

Journals

add a link to your pcomp journals below with your name:

  1. Melanie Clemmons
  2. Ania Wagner" <hi.aniawagner@gmail.com>
  3. Greg Borenstein
  4. David Phillips" <dp1244@nyu.edu>
  5. Ian Cleary" <ic525@nyu.edu>
  6. Michelle Temple
  7. Steve Aquillano
  8. Mike Knuepfel" <mk3321@nyu.edu>
  9. Jenine Durland" <jd1783@nyu.edu>
  10. Christine Nguyen" <cqn200@nyu.edu>
  11. Hana Newman
  12. Melissa Clarke" <mcnco@earthlink.net>
  13. Noah King
  14. Peiyu Liu" <pl874@nyu.edu>
  15. Peter Holzkorn
  16. Sean Fitzgerald
  17. Susan Ngo
  18. Tianwei Liu

Weekly Links

Week 1:

  • Blinky From Class
void setup()
{
  pinMode(2, OUTPUT);      // sets the digital pin as output
  pinMode(3, INPUT);
}

void loop()
{
  if (digitalRead(3)){
    digitalWrite(2, HIGH);   // sets the LED on
    delay(1000);                  // waits for a second
    digitalWrite(2, LOW);    // sets the LED off
    delay(1000);                  // waits for a second
  }
}

Week 2:

Week 3:

Tom's Greatest Hits

  if (input > biggestNumberIEverSaw){
    biggestNumberIEverSaw = input;
  }
  input = map(input, 800,biggestNumberIEverSaw,0,255);

Week 4

    * PROCESSING CIRCLE 

import processing.serial.*;

Serial myPort; int input;

void setup(){

  size(800,600);
  println(Serial.list());
  myPort = new Serial(this, "COM28", 9600); 
  ellipseMode(CENTER);

}

void draw(){

  background(255);
  ellipse(width/2,height/2,input*5,input*5);

} void serialEvent(Serial p) {

  input = p.read();
  println("input" + input);

}

    * PROCESSING GRAPH 

import processing.serial.*;

Serial myPort; int input; int xpos;

void setup(){

  size(800,600);
  println(Serial.list());
  myPort = new Serial(this, "COM28", 9600); 
  background(255);

}

void draw(){

  ellipse(xpos,input,2,2);
  xpos++;
  if (xpos > width){
    xpos = 0;
    background(255);
  }

} void serialEvent(Serial p) {

  input = p.read();
  println("input" + input);

}

Week 7

Arduino

 int heat = 65; int light = 65; int onOff = 0;

void setup() {

  Serial.begin(9600);
  pinMode(4, INPUT); 
  pinMode(7, OUTPUT); 
  Serial.println("Start");

}

void loop() {

  if (Serial.available() > 0){  //only send if you have hear back
    int input = Serial.read();
    input = map(input,0,255,500,2500);    // convert the analog value
    // to a range between minPulse
    Serial.println(input);
    digitalWrite(7, HIGH);   // Turn the motor on
    delayMicroseconds(input);       // Length of the pulse sets the motor position
    digitalWrite(7, LOW);    // Turn the motor off

    heat  = analogRead(5);
    light  = analogRead(0);
    onOff = digitalRead(4);

    Serial.print(heat);
    Serial.print(",");
    Serial.print(light);
    Serial.print(",");
    Serial.print(onOff);
    Serial.print(",");

    Serial.print(10, BYTE);  //send a return
    //Serial.flush();
   delay(20);  //you might use this instead of if available
  }

}

Procressing

import processing.serial.*;

float bgColor; // Background color

Serial port; // The serial port float xpos; // position of the ball float ypos ; int shape;

void setup() {

  size(800, 600);  // Stage size
  ypos = height*3/4;
  xpos = width/4;
  noStroke();      // No border on the next thing drawn
  ellipseMode(CENTER);
  rectMode(CENTER);

  // Print a list of the serial ports, for debugging purposes to find out what your ports are called:
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);  //you can pull the name out of the list
  //port = new Serial(this, "/dev/tty.BlueRadios-COM0-1", 9600);  //or you can just specify it
  port.write(65);    // Send a capital A in case the microcontroller is waiting to hear from you
  // println("OKAY LET'S GO");

}

void draw() {

  background(0);
  fill(255-bgColor,0,0);
  // Draw the shape
  if (shape == 0){
    ellipse(xpos, ypos, 60, 60);
  }
  else{
    rect(xpos, ypos, 60, 60);
  }

}

void serialEvent(Serial port) {

  String input = port.readStringUntil(10);  //make sure you return (Ascii 13) at the end of your transmission
  if (input != null){
    print("Raw Input: " + input);
    String[] parts = input.split(",");  //this will only work if you put commas (Ascii 44) between things in your transmission
    if (parts.length >= 3){
      ypos = int(parts[0]);
      ypos = map(ypos,300,900,height,0);  //400 and 625 were arrived at emperically by looking at readings from the sensor
      bgColor =  int(parts[1]);
      bgColor = map(bgColor,430,550,0,255); 
      shape = int(parts[2]);
      float mouseDistanceAcross = map(mouseX,0,width,0,255);
      port.write(int(mouseDistanceAcross)); //in this example you might use the mouse distance across to control the panning of a servo motor

    }
  }

}

Week 7 ACCELEROMETER + RGB LED

ARDUINO SIDE

int analogReading; //variable int size because adc number potentially as big as 1024

void setup() {

  beginSerial(9600);  //set up communication back to pc
  //don't forget to press "serial monitor button"

}

void loop() {

  analogReading = analogRead(5); //can only use pins 0-5
  Serial.print(analogReading,DEC);
  Serial.print(44,BYTE);
  analogReading = analogRead(4); //can only use pins 0-5
  Serial.print(analogReading,DEC);
  Serial.print(44,BYTE);
  analogReading = analogRead(3); //can only use pins 0-5
  Serial.print(analogReading,DEC);
  Serial.print(44,BYTE);
  Serial.println(10,BYTE); //talk back to pc
  if (Serial.available() >=3){
    int r = Serial.read();
    int g = Serial.read();
    int b = Serial.read();
    analogWrite(6,b);
    analogWrite(5,6);
    analogWrite(11,g);
  }
  delay(20);

}

PROCESSING SIDE import processing.serial.*;

Serial port; // The serial port int xpos, ypos; // position of the ball int r,g,b;

void setup() {

  size(255, 255);  // Stage size

  ellipseMode(CENTER);

  xpos = width/2;
  ypos = height/2;
  // Print a list of the serial ports, for debugging purposes to find out what your ports are called:
  println(Serial.list());
  //port = new Serial(this, Serial.list()[0], 9600);  //you can pull the name out of the list
  port = new Serial(this, "COM28", 9600);  //or you can just specify it
  sendColors();  // Send stuff in case the microcontroller is waiting to hear from you

}

void sendColors(){

  port.write(r);
  port.write(g);
  port.write(b); 
  //println("R" + r+ " G" + g + " B" + b);

}

void draw() {

  for(int i=0; i<width; i++) {
  for(int j=0; j<height; j++) {
    stroke(0, i, j);
    point(i, j);
  }

}

  int thisPixel = get(xpos,ypos);
  r = int(red(thisPixel));
  g = int(green(thisPixel));
  b = int(blue(thisPixel));
  fill(255,255,255);
  ellipse(xpos,ypos,10,10);

}

void serialEvent(Serial port) {

  String input = port.readStringUntil(10);  //make sure you return (Ascii 13) at the end of your transmission
  if (input != null){
    print("Raw Input: " + input);
    String[] parts = input.split(",");  //this will only work if you put commas (Ascii 44) between things in your transmission
    if (parts.length > 2){ //make sure it is a full valid message
      //turn them from ASCII into numbers
      int xtilt = int(parts[0]);
      int ytilt = int(parts[1]);
      if (xtilt > 500) {
        xpos = xpos + 1 ;// same as xpos++
      }
      else {
        xpos = xpos - 1 ;// same as xpos--
      }
      xpos = min(xpos,width);
      xpos = max(xpos,0);
      if (ytilt > 500) {
        ypos = ypos + 1 ;// same as ypos++
      }
      else {
        ypos = ypos - 1 ;// same as ypos--
      }
      ypos = min(ypos,width);
      ypos = max(ypos,0);
      println("Positionx:" + xpos + " y:" + ypos );
      sendColors();
    }
  }

}

2 analog, 1 switch and a servo

ARDUINO

int heat = 65; int light = 65; int onOff = 0;

void setup() {

  beginSerial(9600);
  pinMode(4, INPUT); 
  pinMode(2, OUTPUT); 

}

void loop() {

  if (Serial.available() > 0){  //only send if you have hear back
    int input = Serial.read();
    input = map(input,0,255,500,2500);    // convert the analog value
    // to a range between minPulse
    digitalWrite(2, HIGH);   // Turn the motor on
    delayMicroseconds(input);       // Length of the pulse sets the motor position
    digitalWrite(2, LOW);    // Turn the motor off


    heat  = analogRead(5);
    light  = analogRead(0);
    onOff = digitalRead(4);

    Serial.print(heat,DEC);
    Serial.print(44, BYTE);
    Serial.print(light,DEC);
    Serial.print(44, BYTE);
    Serial.print(onOff,DEC);
    Serial.print(44, BYTE);

    Serial.print(10, BYTE);  //send a return
    delay(20);  //you might use this instead of if available
  }

}

PROCESSING import processing.serial.*;

float bgColor; // Background color

Serial port; // The serial port float xpos; // position of the ball int shape;

void setup() {

  size(256, 256);  // Stage size
  noStroke();      // No border on the next thing drawn
  ellipseMode(CENTER);
  rectMode(CENTER);

  // Print a list of the serial ports, for debugging purposes to find out what your ports are called:
  println(Serial.list());
  //port = new Serial(this, Serial.list()[0], 9600);  //you can pull the name out of the list
  port = new Serial(this, "COM30", 9600);  //or you can just specify it
  port.write(65);    // Send a capital A in case the microcontroller is waiting to hear from you
  // println("OKAY LET'S GO");

}

void draw() {

  background(bgColor);
  fill(255,0,0);
  // Draw the shape
  if (shape == 0){
    ellipse(xpos, height/2, 20, 20);
  }
  else{
    rect(xpos, height/2, 20, 20);
  }

}

void serialEvent(Serial port) {

  String input = port.readStringUntil(10);  //make sure you return (Ascii 13) at the end of your transmission
  if (input != null){
    println("Raw Input: " + input);
    String[] parts = input.split(",");  //this will only work if you put commas (Ascii 44) between things in your transmission
    if (parts.length >= 3){


      bgColor =  int(parts[0]);
      bgColor = map(bgColor,500,1000,0,255);  

      xpos = int(parts[1]);
      xpos = map(xpos,500,580,0,width);  //400 and 625 were arrived at emperically by looking at readings from the sensor

      shape = int(parts[2]);

      float mouseDistanceAcross = map(mouseX,0,width,0,255);
      port.write(int(mouseDistanceAcross)); //in this example you might use the mouse distance across to control the panning of a servo motor
    }
  }

}

Week 7

Week 10


int r,g,b;

void setup() {

  Serial.begin(9600);  //set up communication back to pc
  //don't forget to press "serial monitor button"

}

void loop() {

  int analogReading = analogRead(5); //can only use pins 0-5
  Serial.print(analogReading);
  Serial.print(",");
  analogReading = analogRead(4); //can only use pins 0-5
  Serial.print(analogReading);
  Serial.print(",");
  analogReading = analogRead(3); //can only use pins 0-5
  Serial.print(analogReading);
  Serial.print(",");
  Serial.println(10,BYTE); //talk back to pc
  if (Serial.available() >=3){
    r = Serial.read();
    g = Serial.read();
    b = Serial.read();
  }
  analogWrite(6,b);
  analogWrite(5,r);
  analogWrite(3,g);
  delay(20);

}


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

int xpos, ypos; // position of the ball

int r,g,b; PImage pic ;

void setup() {

  size(255, 255);  // Stage size
  pic = loadImage("colorspace_RGB.png");
  ellipseMode(CENTER);
  size(pic.width,pic.height);
  xpos = width/2;
  ypos = height/2;
  // Print a list of the serial ports, for debugging purposes to find out what your ports are called:
  println(Serial.list());
  //port = new Serial(this, Serial.list()[0], 9600);  //you can pull the name out of the list
  port = new Serial(this, "/dev/tty.usbserial-A7004nUQ", 9600);  //or you can just specify it
  sendColors();  // Send stuff in case the microcontroller is waiting to hear from you

}

void sendColors(){

  port.write(r);
  port.write(g);
  port.write(b); 

}

void draw() {

  //image of a color space
  image(pic,0,0);

  /*  draw a color space
   for(int i=0; i<width; i++) {
   for(int j=0; j<height; j++) {
   stroke(0, i, j);
   point(i, j);
   }
   }
   */
  //find the color of the pixel at the current spot
  int thisPixel = get(xpos,ypos);
  r = int(red(thisPixel));
  g = int(green(thisPixel));
  b = int(blue(thisPixel));
  //put an ellipse over the spot
  fill(255,255,255);
  ellipse(xpos,ypos,10,10);

}

void serialEvent(Serial port) {

  String input = port.readStringUntil(10);  //make sure you return (Ascii 13) at the end of your transmission
  if (input != null){
    print("Raw Input: " + input);
    String[] parts = input.split(",");  //this will only work if you put commas (Ascii 44) between things in your transmission
    if (parts.length > 2){ //make sure it is a full valid message
      int xtilt = int(parts[0]);
      int ytilt = int(parts[1]);
      xpos = int( map(xtilt,400,600,0,width) );
      ypos = int( map(ytilt,400,600,0,height) );
      sendColors();
    }
  }

}

Week 10

Week 11

Week 12

  Edit | View | History | Print | Recent Changes | Search Page last modified on November 13, 2009, at 11:55 AM