/* Arduino Test Control a LED by mouse, the background color by a switch. The circuit: * inputs - D12: a tactile switch with a pulldown resistor (e.g. 10k ohm) * outputs - D13: a LED with a current-limiting resistor (e.g. 330 ohm) Created 10 May 2009 By Shigeru Kobayashi Modified 13 May 2009 By Shigeru Kobayashi http://funnel.cc/ http://arduino.cc/ http://firmata.org/ */ import processing.funnel.*; Arduino arduino; int switchPin = 12; int ledPin = 13; color backgroundColor = color(50, 50, 50); void setup() { size(200, 200); textFont(createFont("CourierNewPSMT", 12)); Configuration config = Arduino.FIRMATA; config.setDigitalPinMode(switchPin, Arduino.IN); config.setDigitalPinMode(ledPin, Arduino.OUT); arduino = new Arduino(this, config); arduino.digitalPin(switchPin).addFilter(new SetPoint(0.5, 0.1)); } void draw() { background(backgroundColor); for (int i = 0; i < 6; i++) { text("A" + i + ": " + arduino.analogPin(i).value, 10, 20 + 20 * i); } } void mousePressed() { arduino.digitalPin(ledPin).value = 1.0; } void mouseReleased() { arduino.digitalPin(ledPin).value = 0.0; } // on change from 0 to 1 (or non-zero) void risingEdge(PinEvent e) { if (e.target.number == switchPin) { // the switch is pressed backgroundColor = color(255, 50, 50); } } // on change from 1 (or non-zero) to 0 void fallingEdge(PinEvent e) { if (e.target.number == switchPin) { // the switch is released backgroundColor = color(50, 50, 50); } }