Re: [問題] Arduino輸出值到Processing如何辨別A0及A1,2,3
===============================
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
11/19 16:48, 2F
討論串 (同標題文章)