Tag Archives: Processing

Processing, the key for Arduino board independent programming

When it comes to Arduino, there are several ways to do things. Using simple Arduino IDE to communicate with the board through serial port. Write a Java program to do it, or maybe do send orders to Arduino through your program that is not uploaded on Arduino card and can be changed anytime without even updating the pde file on the board. The tool that gives you  the power to do this is called Processing & the library used exactly for Arduino is called StandardFirmdata. The very good thing about Processing is that it is based on Java and all Java codes works right out of the box on it. You can also import processing libraries into your Java framwork and enjoy the power of processing right in the middle of your Java project(in Eclipse).

The instruction to get Processing & Arduino talk together :

  1. Download this file.
  2. Unzip the library and copy the “arduino” folder into the “libraries” sub-folder of your Processing Sketchbook. (You can find the location of your Sketchbook by opening the Processing Preferences. If you haven’t made a “libraries” sub-folder, create one.)
  3. Run Arduino, open the Examples > Firmata > StandardFirmata sketch, and upload it to the Arduino board.
  4. Configure Processing for serial:http://processing.org/reference/libraries/serial/
  5. In Processing, open one of the examples that comes with with the Arduino library(in the same folder that we just unzipped).
  6. Edit the example code to select the correct serial port.
  7. Run the example.

Dashed line at Java/Processing

This code is a little bit edited and re-posted again from a post I found on Processing forum. Check the source at the bottom of the post for the original post.
[java]
import java.awt.*;

float[] dashes = { 16.0f, 8.0f, 4.0f, 8.0f };
BasicStroke pen;

void setup(){
size(400, 400);
noLoop();
pen = new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 4.0f, dashes, 0.0f);
Graphics2D g2 = ((PGraphicsJava2D) g).g2;
g2.setStroke(pen);
}

void draw(){
line(0, 0, width, height);
line(0, height, width, 0);
}
[/java]
source : http://processing.org/discourse/yabb2/YaBB.pl?board=Syntax;action=display;num=1217445670

Processing & Arrow keys

Although in the Processing API it is mentioned that key returns the value of the pressed key, but when it comes to arrows it just returns question mark !!! The magic is to use keyCode :-)

[java]
void keyPressed(){
//print(keyCode);
if (keyCode == RIGHT){
//GO RIGHT
}
else if (keyCode == LEFT){
//GO LEFT
}
<div>else if (keyCode == UP){</div>
<div>//GO UP</div>
<div>}</div>
<div>else if (keyCode == DOWN){</div>
<div>//GO DOWN</div>
<div>}</div>
}//end of keyPressed

[/java]