Thursday, April 21, 2011

Arduino and Java

I've found a tutorial online that related to virtual serial port writing. I've seek help from my house mate which is a IT student because this need a strong IT and Java programming knowledge. Firstly we installed the Netbean software as written in the tutorial:



After that, we import some Arduino IDE libraries and configurations:



After that, we put in the codes that given by the website:


package serialtalk;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;

public class Main {
static InputStream input;
static OutputStream output;

public static void main(String[] args) throws Exception{
Preferences.init();
System.out.println("Using port: " + Preferences.get("serial.port"));
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
Preferences.get("serial.port"));

SerialPort port = (SerialPort)portId.open("serial talk", 4000);
input = port.getInputStream();
output = port.getOutputStream();
port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
while(true){
while(input.available()>0) {
System.out.print((char)(input.read()));
}
}
}
}


We programmed the java file inside Serial Midi Converter hope that when it receive the sound signal fron serial port, it will also trigger virtual space button so that the splash effects will be played. We've tried whole night in figuring where to put in VK_SPACE but it still no improvement. Time really flies that it already early in the morning after we spent so many time on it but show nothing. We will continue to do it after have a sleep first >.<...

Reference:
1. http://silveiraneto.net/2009/03/01/arduino-and-java/

No comments:

Post a Comment