忍者ブログ
Admin*Write*Comment *editedit
@kissatenの脳内デブリ
[2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10]  [11]  [12
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


こんちわ.

Arduinoでセンサの値を取得はできてたのですが、

グラフ化のやり方が良くわからなかったので

英語をよく読みました(最初からこれをしていれば・・・.)


必須・・・Processing

はいはい、こっからダウンロードしてくださいね

http://processing.org/

上側のDownload で自分の機体にあったのを落としてください.

--
【センサの値をグラフ化】
さーて、

Arduino IDEにあったGraph

サンプルの英語をよく読みましょう

Processing使えって書いてますね.


------------Arduino部分--------
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(0));
  // wait a bit for the analog-to-digital converter 
  // to stabilize after the last reading:
  delay(10);
}

---Arduino部分終了---------

/* Processing code for this example
って書いてある処から

「*/」ってところまでがProcessingのコードです.

※C言語は/* */で囲えばコメントになります.

僕なりに日本語を下記足してみました.

---------Processing---------
import processing.serial.*;
 
 Serial myPort;        //とりあえず宣言してっください.
 int xPos = 1;         // horizontal position of the graph
 
 void setup () {
 // 画面の大きさ、小さいと観づらいです.
 size(760, 480);       
 //繋がってるポートをリスト化、
 println(Serial.list());
//Arduinoが繋がってるポートを下の[この中]に入れましょう.
 myPort = new Serial(this, Serial.list()[1], 9600);
 // don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // いろあい?0が黒255が白.ただし一回しか表示されない.あとは黒
 background(0);
 }
 void draw () {
 // everything happens in the serialEvent()
 }
 
 void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 
 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // convert to an int and map to the screen height:
 float inByte = float(inString);
 inByte = map(inByte, 0, 1023, 0, height);
 
 // draw the line:
 stroke(127,34,255);
 line(xPos, height, xPos, height - inByte);
 
 // at the edge of the screen, go back to the beginning:
 if (xPos >= width) {
 xPos = 0;
 background(0);
 }
 else {
 // increment the horizontal position:
 xPos++;
 }
 }
 }
 --------------Processing終わり--------
これをまんま書き込めばいいです.

プログラムおいておきますね.

Processingプログラム ←クリックして先でダウンロード

【実際の表示状態】
Arduinoの方は、サンプルスケッチのGraphを利用してください.

processing.jpg
























これが出力されます

①は削って

②だけが欲しいところですね.

--
【おまけ補足】
Processingで下の画面に表示されるリストは、どのCOMポートが使われているか示すものです.

確認した方がいいですよ.

拍手

PR

  • カレンダー
02 2024/03 04
S M T W T F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
  • 置き場

blogram投票ボタン
----タグクラウド-------
  • 喫茶店プロフ
HN:
kissaten
年齢:
35
HP:
性別:
男性
誕生日:
1988/05/17
職業:
高専生
趣味:
マジック/写真/音楽鑑賞
自己紹介:
写真とかマジックが好きです.
持病があります.
【持病】
SLE(全身性エリテマトーデス ループス腎炎)、大腿骨骨頭壊死.映画鑑賞と読書が好きです.GUMIさんが大事です.
【マジック】
Youtubeの所に動画があります.
クローズアップが得意です.

プロフィールの↓に連絡先があります.
--------------------------
連絡先:
kissaten517☆gmail.com
※”☆”を@にしてね(゚ー゚*)
  • グミプロフ
HN:
GUMI
年齢:
22
性別:
女の子
誕生日:
1988/11/09
職業:
社会に貢献してますよ
趣味:
喫茶店さんをいじること。
自己紹介:
もう婚約者でーすぅ
影の編集者をしております!

あわせて読みたいブログパーツ
free counters
Free counters
  • 最新コメント
[12/01 cartier tortue replique]
[11/24 replique pendentif bulgari or blanc]
[11/22 スーパーコピーブランド ブルガリ]
  • カウンター
  • 最新トラックバック
Copyright © @kissatenの脳内デブリ All Rights Reserved.*Powered by NinjaBlog
Graphics By R-C free web graphics*material by 工房たま素材館*Template by Kaie
忍者ブログ [PR]
ブログパーツ