nick /224 /crarduino


/* nick lally
with help from Jeff Gray, ITP: http://itp.nyu.edu/physcomp/sensors/Code/ThreeSensorsCallResponseHumanReadable
*/

int photoPin = 0;    // first analog sensor
int valPhoto = 0;  //photoCell value
//int secondSensor = 0;   // second analog sensor
//int thirdSensor = 0;    // digital sensor
int inByte = 0;         // incoming serial byte

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  establishContact();  // send a byte to establish contact until Processing responds
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    // read first analog input, no dividing necessary:
    valPhoto = analogRead(photoPin);
    // delay 10ms to let the ADC recover:
    delay(10);
    // read second analog input, no dividing necessary:
    //secondSensor = analogRead(1);
    // read  switch, multiply by 255
    // so that you're sending 100 or 255:
    //thirdSensor = 100 + (155 * digitalRead(2));
    // send sensor values:
    Serial.print("X,");
    Serial.print(valPhoto, DEC);
    //Serial.print(",Y,");
    //Serial.print(secondSensor, DEC);
    //Serial.print(",Z,");
    //Serial.print(thirdSensor, DEC);
    Serial.print("\n");
  }
}

void establishContact() {
 while (Serial.available() <= 0) {
      Serial.print('A', BYTE);   // send a capital A
      delay(300);
  }
}

Page Details
Contact DANM  |  Digital Arts and New Media  |  Arts Division  |  Grad Division
login