/* Bluetooth duplex adapted from Tom Igoe's serial_duplex code Sends a character (single byte) out the serial port to a blueSMIRF device, every 300ms, listens for bytes received, and displays their CHAR value Created 21 October 2006 */ import processing.serial.*; // the serial port: Serial port; // variable to hold keystoke values: int thisByte = -1; // incoming serial data: int whichKey = -1; // font for printing: PFont fontA; void setup() { // window size: size(200, 200); // load and prep fonts to print to window. // use Tools -->Create Font... to make your own font. fontA = loadFont("CourierNewPSMT-48.vlw"); textFont(fontA, 24); // list all the available serial ports: println(Serial.list()); // choose the appropriate serial port from the list - #2 is the com port on my computer // for the BlueSMIRF chip i've paired to port = new Serial(this, Serial.list()[2], 9600); } void draw() { background(0); text("Received: " + char(thisByte), 10, 130); text("Sent: " + char(whichKey), 10, 100); // if there are bytes available in the input buffer, // read them and print them: while (port.available() > 0) { thisByte = port.read(); } } void keyPressed() { // send the keystroke out: char tosend = char(key); port.write(tosend+"\r"); println("sent "+tosend); whichKey = key; }