更新: 私が使用しているコードはここにあります: https://dl.dropbox.com/u/2108381/MyArduinoPlot.java これが私の課題を理解するのに役立つことを願っています。お時間をいただきありがとうございます。
Arduino からセンサー値を読み取り、Java ライブラリ JFreeChart を使用してグラフ化したいと考えています。
インターネットでいくつかのコードを見つけました (以下を参照)。動的折れ線グラフをプロットするためのコードと、Arduino の値を読み取るためのコードを組み合わせたいと思います。両方のコードは別々に動作しますが、両方を組み合わせることに行き詰まりました。
動的折れ線グラフをプロットするためのコードはここからです (ランダム データをプロットします): http://dirtyhandsphp.blogspot.in/2012/07/how-to-draw-dynamic-line-or-timeseries.html
Java で Arduino の値を読み取るコードは次のとおりです: http://arduino.cc/playground/Interfacing/Java
私は(Javaの初心者ですが)関連する部分がここにあると思います:
/**
* Handle an event on the serial port. Read the data and print it.
*/
public synchronized void serialEvent(SerialPortEvent oEvent) {
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
int available = input.available();
byte chunk[] = new byte[available];
input.read(chunk, 0, available);
// Displayed results are codepage dependent
System.out.print(new String(chunk));
// the code I tried
// String MyValue = new String(chunk);
// Double Value = Double.valueOf(MyValue);
} catch (Exception e) {
System.err.println(e.toString());
}
}
// Ignore all the other eventTypes, but you should consider the other ones.
}
そしてここ:
public void actionPerformed(final ActionEvent e) {
// Original Code
final double factor = 0.9 + 0.2*Math.random();
this.lastValue = this.lastValue * factor;
final Millisecond now = new Millisecond();
this.series.add(new Millisecond(), this.lastValue);
System.out.println("Current Time in Milliseconds = " + now.toString()+", Current Value : "+this.lastValue);
// my code
// this.series.add(new Millisecond(), Value);
}
public synchronized void serialEvent
センサー値を返すにはどうすればよいですか? また、それをthis.series.add
パーツに追加するにはどうすればよいですか?
私はJavaの初心者です。
他のウェブサイト/投稿への直接的なヘルプやリンクは大歓迎です。御時間ありがとうございます。