Import Serial Doesnt Work When Exporting Application

edited August 2014 in Arduino

Hi, i have a processing code to read serial input from arduino. Everything works fine when i run the code from Processing, however when I exported the application, the Serial commands dont work anymore. I can see my arduino blinking, which means it is sending the data, but nothing on the processing. Thanks

import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

Serial s;
Robot robot;

float input;

boolean p = false;
void setup(){
  try{
    robot = new Robot();
  }
  catch (AWTException e){
    e.printStackTrace();
  }
  size(500,500);
  background(0);
  s = new Serial(this, "COM5", 9600);
  s.bufferUntil('\n');
  frame.removeNotify(); 
}
void draw(){
  if(input == 1){
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    delay(100);
    input = 0;
  }
  else if(input == 2){
    robot.keyPress(KeyEvent.VK_B);
    robot.keyRelease(KeyEvent.VK_B);
    delay(100);
    input = 0;
  }

}
void serialEvent(Serial s){
  String in = s.readStringUntil('\n');
  if(in != null){
 input = float(in);
  println("Raw Input:" + input);
  }
}

Answers

  • And this is the Arduino Code:

    int button1 = 8;
    int button2 = 9;
    
    void setup(){
      Serial.begin(9600);
      pinMode(button1, INPUT);
      pinMode(button2, INPUT);
    }
    
    void loop(){
      int in1 = digitalRead(button1);
      int in2 = digitalRead(button2);
    
      if(in1 == HIGH && in2 == LOW){
        Serial.println(1);
      }
    
      else if(in1 == LOW && in2 == HIGH){
        Serial.println(2);
      }
      delay(150);
    }
    
  • Fixed by using the new Processing Alpha 3.0a2

  • edited August 2014

    The same as mine, I'll try what you advised. I hope it work.

  • And yeah, what @Navivanuva said is correct! IT TOTALLY WORKED!!! :D Thank you so much sir!

Sign In or Register to comment.