/* Virtual Etch A Sketch using 2 Potentiometers This program reads two analog sensors via serial and draws their values as X and Y Processing Code Christian Nold, 22 Feb 06 */ import processing.serial.*; String buff = ""; String temp = ""; float temporary = 0.0; float screenwidth = 0.0; float xCoordinate = 0; float yCoordinate = 0; int val = 0; int NEWLINE = 10; Serial port; void setup() { size(200, 200); strokeWeight(10); // fat stroke(255); smooth(); port = new Serial(this, "COM2", 9600); // Change this to the correct serial port } void draw() { fill(0,2); // use black with alpha 2 rectMode(CORNER); rect(0,0,width,height); while (port.available() > 0) { serialEvent(port.read()); } point(xCoordinate, yCoordinate); } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial); } else { if (buff.length() > 1) { temp = buff.substring(0, buff.length()-(buff.length()-1)); // this isolates just the beginning sensor identified if(temp.equals("A") == true) { //sensor A value temp = buff.substring(1, buff.length()); temporary = float(temp); xCoordinate = width/(1024/temporary); println(xCoordinate); } if(temp.equals("B") == true) { //sensor B value temp = buff.substring(1, buff.length()); temporary = float(temp); yCoordinate = height/(1024/temporary); println(yCoordinate); } // Clear the value of "buff" buff = ""; } } } /* Virtual Etch A Sketch using 2 Potentiometers This program reads two analog sensors via serial and draws their values as X and Y Arduino Code Christian Nold, 22 Feb 06 */ int potPin = 4; // select the input pin for the potentiometer int potPin2 = 5; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the value coming from the sensor int val2 = 0; // variable to store the value coming from the sensor void setup() { beginSerial(9600); pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { val = analogRead(potPin); // read the value from the sensor val2 = analogRead(potPin2); // read the value from the sensor printString("A"); printInteger(val); // Example identifier for the sensor serialWrite(10); printString("B"); printInteger(val2); // Example identifier for the sensor serialWrite(10); }