// This Processing code receives G-force measurements from // an analog accelerometer that is connected to Arduino analog // input pins 0 and 1. 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 many other programming languages. // // The Arduino board runs "SimpleAnalogFirmata" code, so you // don't need to write any Arduino code! 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() { size(200,200); stroke(255); // connect to the Arduino via serial port at 57600 bps. println(Serial.list()); my_arduino = new Arduino(this, Serial.list()[0], 57600); } void draw() { // clear the canvas background(102); // read two G-force measurements from Arduino analog pins 0 and 1. gx = my_arduino.analogRead(0) - 512; gy = my_arduino.analogRead(1) - 512; // draw a line indicating the G-force value and direction line(100, 100, 100 + gx, 100 + gy); }