2019年11月28日 星期四

week12

1.按第2按鈕第8個角發出聲音
(蓋掉上禮拜程式碼)

void setup() {
  // put your setup code here, to run once:
  pinMode(8,OUTPUT);//8:buzzer
  pinMode(2,INPUT_PULLUP);//2:makerUNO的按鈕

}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2)==LOW)tone(8,520,1000);
  else noTone(8);
}

2.按按鈕發出指定音符音調

去範例程式中對照指定音符對應數字(檔案->範例->02                                                                                                                                                                                                                                                                                                                             ->toneMelody)


int Do=523;
int Re=587;
int Mi=659;
void setup() {
  // put your setup code here, to run once:
  pinMode(8,OUTPUT);//8:buzzer
  pinMode(2,INPUT_PULLUP);//2:makerUNO的按鈕

}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2)==LOW)tone(8,Mi,1000);
  else noTone(8);
}

3.用陣列播放一首歌



int Do=523;
int Re=587;
int Mi=659;
int So=784;
int Fa=698;
int song[13]={So,Mi,Mi,Fa,Re,Re,Do,Re,Mi,Fa,So,So,So};
int now=0;                                                                                                                                                                                                                                       
bool  UP=true;
void setup() {
  // put your setup code here, to run once:
  pinMode(8,OUTPUT);//8:buzzer
  pinMode(2,INPUT_PULLUP);//2:makerUNO的按鈕

}

void loop() {
  // put your main code here, to run repeatedly:
  if(UP&&digitalRead(2)==LOW){tone(8,song[now],1000);
  UP=false;
  now=(now+1)%9;//避免陣列song[now]超過而當掉
  }
  else {
    noTone(8);
    UP=true;
 
  }
  delay(300);
}

4.接單芯線發出聲音


void setup() {
  // put your setup code here, to run once:
  for(int i=2;i<=13;i++){
    pinMode(i,INPUT_PULLUP);
    }
  pinMode(8,OUTPUT);//8:buzzer
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2)==LOW){tone(8,523,200);}
  if(digitalRead(3)==LOW){tone(8,587,200);}
  if(digitalRead(4)==LOW){tone(8,659,200);}
  if(digitalRead(5)==LOW){tone(8,698,200);}
  if(digitalRead(6)==LOW){tone(8,784,200);}
  if(digitalRead(7)==LOW){tone(8,880,200);}
  //8要避開,因為他要output用buzzer發聲(8,....)
  if(digitalRead(9)==LOW){tone(8,988,200);}
  if(digitalRead(10)==LOW){tone(8,1047,200);
}
}
5.網路連線




找電腦ip位址


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


import processing.net.*;

Client client;

void setup(){

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

client.write("Hello");

}

void draw(){

}



沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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