2019年11月28日 星期四

Week12_MakerUNO

1.

void setup() {
  pinMode(8, OUTPUT);
  pinMode(2, INPUT_PULLUP);
}
void loop() {
  if(digitalRead(2)==LOW)tone(8,520,1000);
  else noTone(8);
}

2.

int C=523; int D=587; int E=659;
int F=698; int G=784; int A=880; int B=987;
int song[13]={G,E,E,F,D,D,C,D,E,F,G,G,G};
int now=0;
bool up=true;
void setup() {
  pinMode(8, OUTPUT);
  pinMode(2, INPUT_PULLUP);
}
void loop() {
  if(up && digitalRead(2)==LOW){
    tone(8,song[now],300);
    up=false;
    now=(now+1)%13;
  }
  else up=true;
  delay(100);
}

3.

void setup() {
  for(int i=2;i<=13;i++){
    pinMode(i, INPUT_PULLUP);
  }
  pinMode(8, OUTPUT);
}
void loop() {
  if(digitalRead(2)==LOW) tone(8,523,300);
  if(digitalRead(3)==LOW) tone(8,587,300);
  if(digitalRead(4)==LOW) tone(8,659,300);
  if(digitalRead(5)==LOW) tone(8,698,300);
  if(digitalRead(6)==LOW) tone(8,784,300);
  if(digitalRead(7)==LOW) tone(8,880,300);
  if(digitalRead(9)==LOW) tone(8,988,300);
  if(digitalRead(10)==LOW) tone(8,1047,300);
}

4.

//Server:
import processing.net.*;
Server server;
void setup() {
  size(300,300);
  server=new Server(this,7777);
}
void draw() {
  Client thisClient=server.available();
  while(thisClient != null){
    String now = thisClient.readString();
    if(now!=null) println("Server received: "+now);
  }
}
//Client:
import processing.net.*;
Client client;
void setup() {
  size(200,200);
  client=new Client(this,"127.0.0.1",7777);
}
void draw() {
}
void mousePressed(){
  client.write("Hello");
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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