ARDUINO + PROCESSING
Going through the basics of Arduino + Processing
1. Running a circuit by connecting Arduino and Processing
// Running a circuit by connecting Arduino and Processing
Demo Video :
Programme :
//Arduino (library -> StandardFirmata)
//Processing (library -> arduino_input)
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
color off = color(4, 79, 111);
color on = color(84, 145, 158);
void setup() {
size(470, 280);
// Prints out the available serial ports.
println(Arduino.list());
// Modify this line, by changing the “0” to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
// Having list [0]-[4] need to change according to your computer
arduino = new Arduino(this, Arduino.list()[1], 57600);
// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, “/dev/tty.usbmodem621”, 57600);
// Set the Arduino digital pins as inputs.
for (int i = 0; i <= 13; i++)
arduino.pinMode(i, Arduino.INPUT);
}
void draw() {
background(off);
stroke(on);
// Draw a filled box for each digital pin that’s HIGH (5 volts).
for (int i = 0; i <= 13; i++) {
if (arduino.digitalRead(i) == Arduino.HIGH)
fill(on);
else
fill(off);
rect(420 – i * 30, 30, 20, 20);
}
// Draw a circle whose size corresponds to the value of an analog input.
noFill();
for (int i = 0; i <= 5; i++) {
ellipse(280 + i * 30, 240, arduino.analogRead(i) / 16, arduino.analogRead(i) / 16);
}
}