// This Processing code receives G-force measurements from // an accelerometer that is connected to analog pins 0 and 1 // on an Arduino. It displays these values as a vector. // // To interact with the Arduino board, Processing uses the // "cc.arduino.*" library. Such libraries also exist for // Max/MSP and other programming languages. // // The Arduino board runs standard Firmata code, so you don't // need to write its program. import processing.serial.*; // firmata requires a serial connection import cc.arduino.*; // the firmata library for processing Arduino my_arduino; // declare an object of type "Arduino" int gx, gy; void setup() { // println(Arduino.list()); size(200,200); stroke(255); // connect to my Arduino board via serial port COM17 at 57600 bps. // make sure the baudrate (bps) matches that of the firmata code // uploaded to the Arduino board! my_arduino = new Arduino(this, "COM17", 57600); } void draw() { background(102); // read two G-force measurements from Arduino analog pins 0 and 1. gx = my_arduino.analogRead(0) - 500; gy = my_arduino.analogRead(1) - 500; line(100, 100, 100 + gx, 100 + gy); }