Examples - Wiring Lib - AnalogIn
Wiringlib - Supersonic
This example shows the use of an analog input device using WiringLib in Processing. Connect an infrared sensor to analog pin 0 of your wiring-board. No coding in Wiring required!
Copy this code to your Processing Sketch
// 31 October 2008 // Infrared // by Christoph Wartmann and Etienne Ribeiro import processing.core.*; import gnu.io.*; import Wiring.*; import processing.serial.*; // Const static int analogPin = 0; // Analog pin (where the infrared-sensor is connected) color colDot = color (255, 0, 0); // Color of dot static String comPort = "COM4"; // Var SerialLib objSerialLib; int val = 0; // Setup void setup(){ size(400,400); // Wirng-Object objSerialLib = new Wiring.SerialLib(this, comPort); } // Main-Loop public void draw(){ background (0); // Values form 0 to 1023 objSerialLib.getAnalogInput(analogPin, false); // draw dot fill (colDot); smooth(); ellipse (width/2, height/2, width*val/1024, height*val/1024); // take a break delay(50); } void SerialData(Integer v1, Integer v2, Integer v3, Integer v4, Integer v5, Integer v6, Integer v7, Integer v8) { // write value from sensor to 'val' if ((char)v1.intValue() == 'A' && (char)v2.intValue() == 'I' && v3.intValue() == analogPin) { val = v4.intValue() * 4; } }