Re: [問題] Arduino輸出值到Processing如何辨別A0及A1,2,3

看板ask作者 (梁龍)時間3年前 (2020/11/18 19:31), 編輯推噓1(101)
留言2則, 1人參與, 3年前最新討論串2/2 (看更多)
=============================== Arduino =============================== void setup() { Serial.begin( 9600 ); } void loop() { /* int value = analogRead( A0 ); Serial.write(value/4); */ long value1 = analogRead( A0 ); long value2 = analogRead( A1 ); long valueout = (value1*1000)+(value2); //我這邊假設兩值最大小於1000 所以第一個值*1000 加上第二個值 值比較大用long Serial.write(valueout); delay(0); } =============================== Processing =============================== /* Processing 範例: * 讀取從 Serial Port 傳進來的 Sensor 讀值 * 利用 Sensor 讀值移動矩形 (Rectangle) */ import processing.serial.*; Serial serial; //int sensorValue; long sensorValue; long printValue1; long printValue2; void setup() { // 設定畫布大小為 305 x 200 size(610, 400); // 開啟 Serial port,通訊速率為 9600 bps // 注意! 如果你 Arduino 不是接在 COM4,請做適當調整 serial = new Serial(this, "COM6", 9600); } void draw() { if ( serial.available() > 0) { // 讀取從 Serial Port 傳進來的 Sensor 讀值 sensorValue = serial.read(); println(sensorValue); printValue1 = (sensorValue/1000)/4; printValue2 = (sensorValue%1000)/4;; // 在 (x, y) 為 (sensorValue, 80) 的位置畫一個 50x50 的矩形 background(255); // 白色背景 fill(255,0,0); // 填滿顏色為紅色 //rect(sensorValue, 80, 50, 50); rect(printValue1, 80, 50, 50); rect(printValue1, 140, 50, 50); } 上色是我添加的片段 沒有編譯器也沒有裝置 請自行debug -- 一流的權力者,懂得有效地善用權力來做事;二流的權力者,則只是千方百計想著如何保 住自己手中的權力,藉機坐大。而目前的權力階層,很明顯的只能算是二流以下的權力者 。 銀河英雄傳說 第三集 第三章 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.208.100 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/ask/M.1605699097.A.FB6.html

11/19 16:48, 3年前 , 1F
感謝你,我有用這個概念改了一下成功做出兩個,但我其實
11/19 16:48, 1F

11/19 16:48, 3年前 , 2F
是要十個,這個方法我就Fail了QQ
11/19 16:48, 2F
文章代碼(AID): #1VjGOP-s (ask)
文章代碼(AID): #1VjGOP-s (ask)