Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

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


Sixth Week

Code from class below

Notes on your midterms

  • sam griffin michael's inspirations
  • mindy & andrew & jee's
     **fun house inspired
  • see also ku
  • aron & k's
     **performative interfaces
  • carbon & milena
     **Gloved performances
  • gordie, emily, liana
     **alternative interfaces
  • brian, laura
     **interactive kiosks, bringing people together in unexpected places like museums,cabinets of curiosities/wonder

Punctuation Method :: Arduino code

int analogOne = 0;       // analog input 
int analogTwo = 1;       // analog input 
int digitalOne = 2;      // digital input 

int sensorValue = 0;     // reading from the sensor

void setup() {
  // configure the serial connection:
  Serial.begin(9600);
  // configure the digital input:
  pinMode(digitalOne, INPUT);
}

void loop() {
  // read the sensor:
  sensorValue = analogRead(analogOne);
  // print the results:
  Serial.print(sensorValue, DEC);
  Serial.print(",");

  // read the sensor:
  sensorValue = analogRead(analogTwo);
  // print the results:
  Serial.print(sensorValue, DEC);
  Serial.print(",");

  // read the sensor:
  sensorValue = digitalRead(digitalOne);
  // print the last sensor value with a println() so that
  // each set of four readings prints on a line by itself:
  Serial.println(sensorValue, DEC);
}

Punctuation:: Processing Code

import processing.serial.*;     // import the Processing serial library
Serial myPort;                  // The serial port

float bgcolor;			     // Background color
float fgcolor;			     // Fill color
float xpos, ypos;		             // Starting position of the ball

void setup() {
  size(640,480);

  // List all the available serial ports
  println(Serial.list());

  myPort = new Serial(this, Serial.list()[0], 9600);

  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil('\n');
//don't draw a line around the circle
 noStroke();
}

void draw() {
  background(bgcolor);
  fill(fgcolor);
  // Draw the shape
  ellipse(xpos, ypos, 20, 20);
}

// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the  byte value set in the bufferUntil() 
// method in the setup():

void serialEvent(Serial myPort) { 
  // read the serial buffer:
  String myString = myPort.readStringUntil('\n');
  // if you got any bytes other than the linefeed:
  if (myString != null) {

    myString = trim(myString);

    // split the string at the commas
    // and convert the sections into integers:
    int sensors[] = int(split(myString, ','));

    // print out the values you got:
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); 
    }
    // add a linefeed after all the sensor values are printed:
    println();
    if (sensors.length > 1) {
//lab code has these values mapped to accelerometers, since I used a pot, i changed the mapping to 0, 1023
//adjust appropriately for your inputs
      xpos = map(sensors[0], 0,1023,0,width);
      ypos = map(sensors[1], 0,1023,0,height);
      fgcolor = sensors[2] * 255;
    }
  }
}

call n response Method :: Ardy code

also referred to as handshake

int analogOne = 0;       // analog input 
int analogTwo = 1;       // analog input 
int digitalOne = 2;      // digital input 

int sensorValue = 0;     // reading from the sensor

void setup() {
  // configure the serial connection:
  Serial.begin(9600);
  // configure the digital input:
  pinMode(digitalOne, INPUT);

establishContact(); 
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    int inByte = Serial.read();
  // read the sensor:
  sensorValue = analogRead(analogOne);
  // print the results:
  Serial.print(sensorValue, DEC);
  Serial.print(",");

  // read the sensor:
  sensorValue = analogRead(analogTwo);
  // print the results:
  Serial.print(sensorValue, DEC);
  Serial.print(",");

  // read the sensor:
  sensorValue = digitalRead(digitalOne);
  // print the last sensor value with a println() so that
  // each set of four readings prints on a line by itself:
  Serial.println(sensorValue, DEC);
  }
}

void establishContact() {
 while (Serial.available() <= 0) {
      Serial.println("hello");   // send a starting message
      delay(300);
  }
}


call n response:: Processing

import processing.serial.*;     // import the Processing serial library
Serial myPort;                  // The serial port

float bgcolor;			     // Background color
float fgcolor;			     // Fill color
float xpos, ypos;		             // Starting position of the ball

boolean firstContact = false; // Whether we've heard from the microcontroller 

void setup() {
  size(640,480);

  // List all the available serial ports
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino module, so I open Serial.list()[0].
  // Change the 0 to the appropriate number of the serial port
  // that your microcontroller is attached to.
  myPort = new Serial(this, Serial.list()[0], 9600);

  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil('\n');
//don't draw a line aroundf the ellipse
noStroke();
}

void draw() {
  background(bgcolor);
  fill(fgcolor);
  // Draw the shape
  ellipse(xpos, ypos, 20, 20);
}

// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the  byte value set in the bufferUntil() 
// method in the setup():

void serialEvent(Serial myPort) { 
  // read the serial buffer:
  String myString = myPort.readStringUntil('\n');
  // if you got any bytes other than the linefeed:
  if (myString != null) {

    myString = trim(myString);

    // if you haven't heard from the microncontroller yet, listen:
    if (firstContact == false) {
      if (myString.equals("hello")) { 
        myPort.clear();          // clear the serial port buffer
        firstContact = true;     // you've had first contact from the microcontroller
        myPort.write('A');       // ask for more
      } 
    } 
    // if you have heard from the microcontroller, proceed:
    else {
      // split the string at the commas
      // and convert the sections into integers:
      int sensors[] = int(split(myString, ','));

      // print out the values you got:
      for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
        print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); 
      }
      // add a linefeed after all the sensor values are printed:
      println();
      if (sensors.length > 1) {
//lab code has these values mapped to accelerometers, since I used a pot, i changed the mapping to 0, 1023
//adjust appropriately for your inputs
      xpos = map(sensors[0], 0,1023,0,width);
      ypos = map(sensors[1], 0,1023,0,height);
        fgcolor = sensors[2] * 255;
      }
    }
    // when you've parsed the data you have, ask for more:
    myPort.write("A");
  }
}
}
  Edit | View | History | Print | Recent Changes | Search Page last modified on January 17, 2013, at 11:47 AM