Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2958|回復: 0
打印 上一主題 下一主題

arduino 連接 processing

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-11-19 13:18:17 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
我想從 arduino 傳送數據到 processing我是使用分別 兩邊都寫程式 來傳送
可是目前只知道 如何傳送一個數據
想知道如何傳送分別三個 請問程式要如何改
arduino

int Red = 0;
int Green = 1;
int Blue = 2;

void setup(){
  Serial.begin(9600);
}

void loop(){
  int val1 = analogRead(Red);
  int val2 = analogRead(Green);
  int val3 = analogRead(Blue);
  Serial.write(val1);
  Serial.write(val2);
  Serial.write(val3);
  delay(150);
}


processing

import processing.serial.*;

Serial serial;
int Red;
int Green;
int Blue;

void setup(){
  size(305,200);

  serial = new Serial(this, "COM17", 9600);
}

void draw(){
  if(serial.available() >0){
    Red = serial.read();
    Green = serial.read();
    Blue = serial.read();
    println(Red);

    background(255);
    fill(255,0,0);
    rect(Green, 80, 50, 50);
    //fill(0 ,0 ,0);
    //rect(Green , 90 ,50 ,50);
  }
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-11 23:45 , Processed in 0.190237 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表