// wiring_in // David A. Mellis // 22 May 2005 // *** WARNING *** // YOU NEED TO CHANGE THE SECOND ARGUMENT OF beginWiring() BELOW TO THE // SERIAL DEVICE OF YOUR WIRING BOARD!!! // An example using the Wiring library for input. // For more information, see: http://dam.mellis.org/w4p/ // // Draws a stylized Wiring board showing the values read on each pin. // The digital pins are bright orange if high (5 volts), dark orange if // low (0 volts). The analog pins are blue, and get brighter the more // voltage is applied to them. Because most of the pins are floating // (unconnected), they will tend to flicker randomly. // This example doesn't use the serial library directly, but this import // statement must be included or Processing won't find the native serial // library. import processing.serial.*; import org.mellis.wiring.*; // declare a global Wiring object Wiring wiring; void setup() { size(420, 256); // initialize the Wiring library // Be sure that the second argument is the serial device used by // Wiring (i.e. the selected item in the Tools | Serial Port menu // in Wiring). On Windows, this will be something like "COM4"; // on the Mac, something like "/dev/tty.usbserial-1B1". To get a // list of available ports, use this line of Processing code: // println(Serial.list()); // Be sure to connect the Wiring board first or it won't show up in // the list. wiring = new Wiring(this, "/dev/tty.usbserial-1B1"); // use all digital pins as inputs for (int i = 0; i < 39; i++) wiring.pinMode(i, wiring.INPUT); } void draw() { background(0); noStroke(); // digital pins for (int i = 0; i < 40; i++) { // check the voltage on each digital pin if (wiring.digitalRead(i) == wiring.LOW) fill(110, 51, 0); else fill(221, 102, 0); // draw pins 0 to 23 across the bottom, 24 to 39 on top if (i < 24) rect(12 + i * 12 + i / 8 * 12, 236, 8, 8); else rect(12 + (i - 24) * 12 + (i - 24) / 8 * 12, 12, 8, 8); } // analog input pins for (int i = 0; i < 8; i++) { // analogRead returns values from 0 (0 volts) to 1023 (5 volts), // so we have to divide by 4. fill(0, 0, wiring.analogRead(i) / 4); rect(12 + (i + 16) * 12 + 24, 12, 8, 8); } // draw the pwm (analog output) pins for (int i = 0; i < 6; i++) { fill(100); rect(12 + (i + 24) * 12 + 36, 12, 8, 8); } // draw the power and ground pins for (int i = 0; i < 4; i++) { fill(100); rect(12 + (i + 24) * 12 + 48, 236, 8, 8); } // draw the USB plug fill(150); rect(348, 172, 72, 36); }