2019年12月5日 星期四

06160832

今天先確認連線

import processing.net.*;

Client client;

void setup(){

size(100,100);///老師的serverIP:120.125.70.53

client = new Client(this, "120.125.70.53", 6666);

}

void draw(){

}

void mousePressed(){

client.write("Hello你好帥");

}

arduino按鈕
void setup() {
  pinMode(2,INPUT);

}

void loop() {
 analogRead(A0);
  analogRead(A1);
  digitalRead(2);

}

2
發出聲音

void setup() {
  pinMode(2,INPUT);

}

void loop() {
 int x=analogRead(A0);
  tone(8,x);

}

3
將座標訊號傳給電腦

void setup() {
  Serial.begin(9600);
}
void loop() {
 int x=analogRead(A0);
  int y=analogRead(A1);

  Serial.print(x);
  Serial.print(" ");
  Serial.print(y);
  Serial.println();
  delay(100);

}

搖桿驅動程式
import processing.serial.*;
Serial serial;
void setup(){
size(1024,1024);///老師的serverIP:120.125.70.53
serial = new Serial(this,"COM5",9600);///看你的COM
}
int x=512,y=512;
void draw(){
    background(255);
    if(serial.available()>0){
        String now=serial.readString();
        String[] xy=splitTokens(now);
        x = int(xy[0]);
        y = int(xy[1]);
    }
    fill(255,0,0);
    ellipse(x,y,100,100);
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...