// Processing code for Sparkfun BlueTooth Test // // sends and receives data from an arduino with an oldish // SparkFun BlueTooth module connected. // // details here: // http://wiki.dxarts.washington.edu/groups/general/wiki/5e22f/Using_Sparkfun_BlueTooth_Module.html // // rtwomey@u.washington.edu, Feb 2013 import processing.serial.*; Serial myPort; void setup() { //set up window, though all the action will occur in the text output zone size(200, 200); // List available ports println(Serial.list()); // Open the port that is the bluetooth device. // you must have already setup the bluetooth device-- // on OS X you simply select the bluetooth icon, Setup Bluetooth Device" // use 1234 for the passcode for Sparkfun BTM-182 myPort = new Serial(this, Serial.list()[4], 9600); println("connected to "+Serial.list()[4]); } void draw() { for(int i=0; i<256; i++) { // loop through 256 binary values myPort.clear(); // dump any stray data myPort.write(i); // send current i to bluetooth device print("Sent: "); // echo info to log window print(int(i)); print(" -> "); delay(100); // wait a bit while (myPort.available() > 0) { // read new data int inByte = myPort.read(); print("Received: "); // echo to log window print(inByte); } println(); } }