2019年11月28日 星期四

week_12嗨

按鈕音樂
int C =523;
int D =587;
int E =659;
int F =698;
int G =784;
int count = 0;
int in[13] = {G,E,E,F,D,D,C,D,E,F,G,G,G};
bool UP = true;
void setup() {
  // put your setup code here, to run once:
  pinMode(8, OUTPUT);
  pinMode(2, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(UP && digitalRead(2) == LOW) {
    tone(8,in[count],200);
    UP = false;
    count++;
  }
  else {
    UP = true;
    if(count > 13){
      count = 0;
    }
  }
  delay(100);
}
觸電音樂
int song[9]={523,587,659,698,784,880,0,988};
void setup() {
  for(int i = 2; i <= 13;i++){
    pinMode(i, INPUT_PULLUP);
  }
  pinMode(8,OUTPUT);
}
void loop() {
  for(int i = 2; i<11;i++){
    if(i == 8) continue;
    if(digitalRead(i) == LOW) tone(8,song[i-2],200);
  }

}

P server

  
import processing.net.*;

Server server;

void setup() {
  size(200, 200);
  server = new Server(this, 7777); 
}

void draw() {
  Client thisClient = server.available();
  if(thisClient != null){
    String now = thisClient.readString();
    println(now);
  }
}
P client
  
import processing.net.*; 

Client client; 
int dataIn; 
 
void setup() { 
  size(200, 200); 

  client = new Client(this, "172.16.67.159", 7777); 
} 
 
void draw() { 

} 
void mousePressed(){
  client.write("M11");
}


沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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