/* Simple program to demonstrate a2d functionality and IR rangefinding. A Sharp 2YOA02 distance sensor is connected to an ADC pin on the microprocessor, and distance data is fed through the serial port to this program. */ import processing.serial.*; Serial port; // Create object from Serial class int val; // Data received from the serial port float MULTIPLIER = 1.6; // Scales readings to full color range. void setup() { size(600, 600); // Open the port that the board is connected to and use the same speed (57600 bps) port = new Serial(this, Serial.list()[0],57600); } void draw() { if (0 < port.available()) { // If data is available, val = port.read(); // read it and store it in val } background(0, val*MULTIPLIER, 0); // color the window proportional to distance reading. }