/* Serial call-and-response by Tom Igoe (with adjustments by Dan) Sends a byte out the serial port, and reads 1 byte in. sets x location a rect Updated October 12, 2004 */ int xpos; // x location of rectangle BFont font; //change this value for different sensors byte response = 2; void setup() { //begin serial communication beginSerial(); size(255, 200); font = loadFont("Garamond-Bold.vlw.gz"); //start off our call and response by sending the value stored in response; serialWrite(response); } void loop() { //draw background with red value from sensor background(0,0,0); textFont(font, 44); fill(255); //display rotation value text(xpos, 5, 30); fill(0,0,255); rectMode(CENTER_DIAMETER); rect(xpos,100, 50, 50); } void serialEvent() { //receive byte xpos = (int) serial; //send # back to ask for another one serialWrite(response); }