arduino + processing code
//Arduino Code
//Arduino code
//ADC + Serial Communication int reading; // the readings from the analog input int inputPin = 0; void setup() { Serial.begin(9600); // initialize serial communication with computer } void loop() { reading = analogRead(inputPin); // read from the sensor Serial.println(reading); // send it to the computer (as ASCII digits) } |
//Processing Code
// Example by Tom Igoe
import processing.serial.*;
int lf = 10; // Linefeed in ASCII
//String myString = null; Serial myPort; // The serial port int i; void setup() {
// List all the available serial ports println(Serial.list()); size (800, 450); // I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); myPort.clear(); // Throw out the first reading, in case we started reading // in the middle of a string from the sender. //myString = myPort.readStringUntil(lf); //myString = null; } void draw() {
background (255); while (myPort.available() > 0) { String myString; myString = myPort.readStringUntil(lf); if (myString != null) { i = int(trim(myString)); println(i); } } ellipse (width/2, height/2, i, 100); } |
'만들기 / making > sensing workshop' 카테고리의 다른 글
serial communication (0) | 2009.08.31 |
---|---|
multi sensor arduino / processing (0) | 2009.08.31 |
Audio sensor module on PCB (0) | 2009.08.31 |
Audio sensor module on Breadboard (0) | 2009.08.31 |
audio sensor processing code (0) | 2009.08.31 |