De War Badge
Actuele versie: http://oud.fablabamersfoort.nl/nl/book/control-processing

Control by Processing

By peteruithoven. Last update on 24 aug 2013.

From Inkscape, save as *.hpgl. And open it using the following Processing script: 

import processing.serial.*;
Serial serial;
volatile String path = "-";

void setup() {
  size(400,150);  
  println(Serial.list());
  //String portName = Serial.list()[0];
 serial = new Serial(this, "/dev/tty.usbserial-A800dpmc", 9600);
}

void mousePressed() {
 selectInput("Select *.hpgl file:", "fileSelected");
}

void keyPressed() {
  selectInput("Select *.hpgl file:", "fileSelected");
}

void draw() {
  background(220,220,220);
  fill(0);
  text("Click anywhere or press any button to open file",50,75);
  if(path != "-") {
    String lines[] = loadStrings(path);
    println(lines.length); 
    for (int i = 0; i < lines.length; i++) { 
      println(lines[i]);
      serial.write(lines[i]);
    }
    serial.write("Ec%0A;EcE;");
    path = "-";
  }
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    path = selection.getAbsolutePath(); 
  }
}