2019年12月5日 星期四

瑋的筆記week13

今天是星期四雨天
//Client 可以是任何人

import processing.net.*;

Client client;

void setup() {

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

  client = new Client(this, "120.125.70.53", 6666);
  ///連線至老師的IP位置
 ///將自己的IP發送至老師那邊
}

void draw() {
}

void mousePressed() {

  client.write("Hello辛苦了");
///上面是發送Hello給連線端
}

這是第二個運用新的玩具?
void setup() {
  // put your setup code here, to run once:
  //pinMode(2,INPUT);//因為他有電可以自己拉高
  pinMode(8,OUTPUT);///聲音
}

void loop() {
  // put your main code here, to run repeatedly:
  int x=analogRead(A0);
  ///analogRead(A0);//X軸0...1023
  ///analogRead(A1);//Y軸0...1023
  ///digitalRead(2);////按下去的button
  tone(8,x);
}
上面這個要搭配麵包板然後將線接好來
像是說接地要接地
5V接5V這樣子才可以成功
像是下面這樣
然後下一個程式碼是
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int x=analogRead(A0);
  int y=analogRead(A1);
  Serial.print(x);
  Serial.print("");
  Serial.print(y);
  Serial.println();
  delay(100);
}
上面這個程式碼是可以告知我們說今天搖桿的角度等等
以便我們去操控。
下面是第四個程式碼
這是運用P語言
import processing.serial.*;
Serial serial;
void setup() {
  size(1024,1024);
  serial =new Serial(this,"COM4",9600);
}
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);
}
然後是運用P語言將搖桿移動的畫面顯示在上面

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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