|
Intro to Physical Computing Syllabus Research & Learning Other Class pages
ITP Help Pages |
Tom GerhardtFall10.TomGerhardt HistoryHide minor edits - Show changes to markup November 01, 2010, at 07:59 PM
by -
Changed lines 26-158 from:
The Absolute Machine to:
The Absolute Machine MULTI-SENSOR SERIAL CODEThe Processing Code:import processing.serial.Serial; public static int packetSize = 4; int readBuffer[] = new int[ packetSize ]; int readBufferPos = 0; int endOfPacket = 255; int currentVals[] = new int[ packetSize ]; int latestValue = 0; Serial ser; void setup() { size( 300,300 );
// println( Serial.list());
ser = new Serial( this,"/dev/tty.usbserial-FTF3JUAW", 9600 );
} void draw() { background( 255 );
//draw circles
for( int v=0;v<packetSize;v++ )
{
pushMatrix();
{
//x
if( v==0 || v==1 ) translate( 200,0 );
else translate( 100,0 );
//y
if( v==1 || v==2 ) translate( 0,200 );
else translate( 0,100 );
//draw
this.ellipse( 0,0,currentVals[v]*0.4f,currentVals[v]*0.4f );
}
popMatrix();
}
} void serialEvent( Serial p ) { int inByte = p.read();
//check bounds
if( inByte < 0 || inByte > 255 ) return;
//check for end of packet
if( inByte == endOfPacket )
{
processPacket( readBuffer );//send vals
readBufferPos = 0;//reset pos
return;//exit
}
//check for overflow
if( readBufferPos >= packetSize )
{
readBufferPos = 0;//reset buffer pos
return; //exit
}
//record
readBuffer[ readBufferPos ] = inByte;
readBufferPos++;
} void processPacket( int[] packet ) { if( packet.length != packetSize ) return;
//record
for( int v=0;v<packetSize;v++ )
{
currentVals[v] = packet[v];
}
// println( packet[0] + "\t" + packet[1] + "\t" + packet[2] + "\t" + packet[3] );
} The Arduino Code:int analogIn0 = 0; int analogIn1 = 0; int analogIn2 = 0; int analogIn3 = 0; void setup() { Serial.begin( 9600 ); } void loop() { //read all analog inputs analogIn0 = analogRead( 0 ); analogIn1 = analogRead( 1 ); analogIn2 = analogRead( 2 ); analogIn3 = analogRead( 3 ); //scale vals 0-254 (255 reserved for end of packet) analogIn0 = analogIn0 * 0.25; analogIn1 = analogIn1 * 0.25; analogIn2 = analogIn2 * 0.25; analogIn3 = analogIn3 * 0.25; //check bounds if( analogIn0 > 254 ) analogIn0 = 254; if( analogIn1 > 254 ) analogIn1 = 254; if( analogIn2 > 254 ) analogIn2 = 254; if( analogIn3 > 254 ) analogIn3 = 254; //send packet Serial.print( analogIn0, BYTE ); Serial.print( analogIn1, BYTE ); Serial.print( analogIn2, BYTE ); Serial.print( analogIn3, BYTE ); Serial.print( 255, BYTE); //end packet //delay //delay( 10 ); } September 13, 2010, at 03:33 PM
by -
Changed line 16 from:
'What is pComp?' links: to:
'What is pComp?!?!?!' ...the links: September 13, 2010, at 03:33 PM
by -
Deleted line 22:
Changed line 24 from:
http://www.swiss-miss.com/2009/05/14737.html Ars Electronica Building to:
Ars Electronica Building September 13, 2010, at 03:31 PM
by -
Changed lines 13-14 from:
to:
Changed line 16 from:
'What is pComp' links: to:
'What is pComp?' links: September 13, 2010, at 03:31 PM
by -
Changed lines 15-16 from:
What is pComp Links: to:
'What is pComp' links: Changed line 23 from:
the large: to:
the large: September 13, 2010, at 03:30 PM
by -
Changed lines 11-26 from:
7-9pm Wednesday, why not schedule a time? to:
7-9pm Wednesday, why not schedule a time? CLASS #1 09/13/2010What is pComp Links: the large:
http://www.swiss-miss.com/2009/05/14737.html Ars Electronica Building September 02, 2010, at 09:25 PM
by -
Changed lines 2-3 from:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever';\\it will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. to:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever'; September 02, 2010, at 09:25 PM
by -
Changed lines 2-3 from:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever'; it will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. to:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever';\\it will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. September 02, 2010, at 09:25 PM
by -
Changed lines 2-5 from:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever'. This page will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. to:
this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever'; it will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. September 02, 2010, at 09:24 PM
by -
Changed line 1 from:
Hello there, to:
Hello there,September 02, 2010, at 09:24 PM
by -
Changed lines 7-8 from:
6:30-9pm Monday to:
6:30-9pm Monday, Classroom 20 (next to pComp lab) September 02, 2010, at 09:21 PM
by -
Added lines 6-8:
When is class again?6:30-9pm Monday Changed line 13 from:
7-9pm Wednesday to:
7-9pm Wednesday, why not schedule a time? September 02, 2010, at 09:14 PM
by -
Changed lines 1-3 from:
Office Hours:to:
Hello there, this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever'. This page will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again. I am best reached at:tom-AT-tomgerhardt.com My Office Hours will be:September 02, 2010, at 09:05 PM
by -
Added lines 1-4:
Office Hours:7-9pm Wednesday |