// Example by Tom Igoe import processing.serial.*; Serial myPort; // The serial port int data; int numChars = 26; color[] colors = new color[numChars]; int keyIndex; float keyScale; int rectWidth; void setup() { println(Serial.list()); // 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()[1], 9600); myPort.bufferUntil(0xFF); size(200, 200); noStroke(); background(0); keyScale = 200/numChars-1.0; rectWidth = width/4; // Send a capital A out the serial port //myPort.write(65); println("polling incoming uart data every 250 ms..."); } /*void serialEvent(Serial myPort) { data = myPort.last(); }*/ void draw() { if(keyPressed) { if(key >= 'A' && key <= 'z') { if(key <= 'Z') { keyIndex = key-'A'; } else { keyIndex = key-'a'; } // dump ascii code for keypress to serial device myPort.write(key); println("wrote " + key + " to serial port"); fill(millis()%255); float beginRect = rectWidth/2 + keyIndex*keyScale-rectWidth/2; rect(beginRect, 0.0, rectWidth, height); } } }