顯示具有 05160311_彭立欣 標籤的文章。 顯示所有文章
顯示具有 05160311_彭立欣 標籤的文章。 顯示所有文章

2019年1月5日 星期六

Week13 立欣ㄉ筆記

要準備做期末作品 , 所以要將processing與arduino做結合

01.

安裝驅動


02.
選擇正確的序列埠


03.
選擇正確的開發板

04.
利用processing的範例 SimpleReadProcessing\file\example\libaries\serial\ SimpleRead


05.把50行以後的程式碼搬到arduino


06.
Arduino : 把pinMode的INPUT改為PULLUP_INPUT , 把接腳改成2
Processing : 改成 new Serial的第二個參數改成COM7










Week 17期末作品

我們的期末作品延續期中,搭配Arduino以及按鈕模組,增加使用者與遊戲的互動

黏上保麗龍球,改良難按的小按鈕


遊戲操作


程式碼












2018年12月31日 星期一

Week 12校外參訪

製作光劍

01.把led燈泡一個一個扳開,並將所有燈泡運用焊接串起來

02.一一檢查led燈泡有沒有接對














03.完成光劍




04.還拿到了小恐龍











2018年12月27日 星期四

Week16 期末作品

01.arduino



02.processing

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.serial.*;
Serial myPort;

float[] zombieX=new float[8];
float[] zombieY=new float[8];
PImage imgZombie,imgBG,img,imgBG2;
int state=0;
int remainTime=0;
int score1=0;
int score2=0;

import ddf.minim.*;
Minim minim;
AudioPlayer player;

void reborn(int i){
  zombieX[i]=int (random(3))*135;
  zombieY[i]=10;
}

void setup(){
  size(400,600);
  myPort = new Serial(this,"COM7",9600);
  imgBG= loadImage("BG.jpg");
  img= loadImage("shot.jpg");
  imgBG2= loadImage("BG2.png");
  minim = new Minim(this);
  player = minim.loadFile("456.mp3");
  player.play();
  
  imgZombie=loadImage("zombie2.png");
  for(int i=0;i<8;i++){
    reborn(i);
    zombieY[i]=325-i*50;
  }
}
int old1=0, old2=0, old3=0;
int Button1=0,Button2=0,Button3=0;
void draw(){
  if(state==0){
    drawOP();
  }else if(state==1){
    drawPlayer();
  }else if(state==2){
    drawED();
  }
  getData();
}
byte [] data=new byte[3];
void getData(){
 if(myPort.available()>0){
  myPort.readBytes(data);
  old1=Button1;
  old2=Button2;
  old3=Button3;
  Button1=data[0];
  Button2=data[1];
  Button3=data[2];
  println(data);
  int press= -1;
  if(data[0]==1 && old1==0) press=1;
  else if(data[1]==1 && old2==0)press=2;
  else if(data[2]==1 && old3==0)press=3;
  
  if( press==1 && zombieX[0]==0) killOneZombie();
  else if( press==2 && zombieX[0]==135) killOneZombie();
  else if( press==3 && zombieX[0]==270) killOneZombie();
  else if(press!= -1 ) bad();
  
 }
}
void killOneZombie(){
  for(int i=0;i<8-1;i++){
    zombieX[i]=zombieX[i+1];
  }
  reborn(7);
  score1+=200;
  minim = new Minim(this);
  player = minim.loadFile("bang.wav");
  player.play();
}

void bad(){
 background(255,0,0); 
 score2+=100;
}

void keyPressed(){
  if(key=='1' && zombieX[0]==0) killOneZombie();
  else if(key=='2' && zombieX[0]==135) killOneZombie();
  else if(key=='3' && zombieX[0]==270) killOneZombie();
  else if(key=='z' && state==0) {state=1;remainTime=30*60;}
  else bad();
}

void drawOP(){
  image(imgBG2,0,0,width,height);
  fill(#FFFFFF);
  textSize(30); text("Press z to Play",95,335);
  textSize(26); text("Happy Halloween!",90,395);
}

void drawPlayer(){
  image(imgBG,0,0,width,height);
  image(img,0,480,400,120);
  for(int i=7;i>=0;i--){
    image(imgZombie, zombieX[i],zombieY[i]);
  }  
  fill(#FC0317); textSize(40); text((remainTime+59)/60,5,40);
  remainTime--;
  if(remainTime<=0) state=2;
}

void drawED(){
  image(imgBG,0,0,width,height);
  fill(#FC0317); text("    Game End\nPlus Score:"+score1,55,200);
  fill(#FC0317); text(" Minus Score:-"+score2,10,320);
  fill(#FC0317); text("Score:"+(score1-score2),140,445);
}


03.成品

2018年12月13日 星期四

Week14 立欣ㄉ筆記

01.
安裝驅動


02.
選擇正確的序列埠


03.
選擇正確的開發板


04.
開啟正確的範例程序


05.



06.


07.
控制旋鈕,pin13會閃爍


2018年12月6日 星期四

Week13立欣ㄉ筆記

01.
安裝驅動


02.
選擇正確的序列埠


03.
選擇正確的開發板


04.
開啟正確的範例程序





05.
將複製過去Arduino範例程序


06.
新增程式碼
pinMode(2,INPUT_PULLUP);//MakeUNO的按鈕在pin2

2018年11月22日 星期四

Week8 期中作品




YouTube連結:https://www.youtube.com/watch?v=hm_MRmuP6W4

我們製作的遊戲名稱為shootzombie,按下z鍵開始遊戲,遊戲時間
為30秒,在遊戲時間內,殭屍們會依序往螢幕下方逼近運用鍵盤的
123數字鍵來消除殭屍,如果按錯畫面會閃爍紅色,是個考驗短時
間反應及手指的靈敏度小遊戲。
困難點:加入計時器時因為多畫了背景以至於遊戲畫面被蓋住,那
個部分卡了好久,求助老師後遊戲就可以順利執行了~~還有如何結
束上一個畫面而不是直接覆蓋遊戲畫面

Week11立欣ㄉ筆記

01.USB連接板子安裝CH341SER驅動程式









02.
寫LED燈會由下往上亮的程式碼



03.

播放小星星的程式碼

/*
This example shows how to play melody using only a Maker UNO.
Tutorial page:
  http://makeruno.com.my/playing-melody-using-only-maker-uno/
Original written by:
  26/01/18  Asyraf (Intern), Cytron Technologies
*/
int piezoPin = 8;
int length = 15;
char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";      // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration)
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration)
{
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}
void setup()
{
  pinMode(piezoPin, OUTPUT);
}
void loop()
{
  for (int i = 0; i < length; i++)
  {
    if (notes[i] == ' ')
    {
      delay(beats[i] * tempo);
    } else
      playNote(notes[i], beats[i] * tempo);
    delay(tempo / 2);
  }
}


04.

可以卡歌的程式碼

/*
This example shows how to change melody with push button using only a Maker UNO.
Tutorial page:
  http://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/

Original written by:
  26/01/18  Asyraf (Intern), Cytron Technologies
*/

int piezoPin = 8;
int button = 2;
int lengths = 26;
char jbnotes[] = "eeeeeeegcde fffffeeeeddedg";
int jbbeats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
int length = 15;
char ttlsnotes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
int ttlsbeats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration)
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration)
{
  int LED[]={3,4,5,6,7,9,10,11};///老師寫的第一行是陣列
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
       digitalWrite(LED[i],HIGH);//老師寫的第二行,是要在播聲音前,先把對應的LED亮起
      playTone(tones[i], duration);
      digitalWrite(LED[i],LOW);//老師寫的第三行,是要在播聲音前,先把對應的LED暗掉
    }
  }
}

void setup()
{
 // pinMode(piezoPin, OUTPUT);///解釋:因為樓下那個迴圈,全部都要設OUTPUT,我們就不用留這行 pinMode(8,OUTPUT)
 for(int i=3;i<=13;i++) pinMode(i,OUTPUT);///老師寫的第四行,是在執行之前,把每個腳位,都設成OUTPUT,才會亮 發聲音
 pinMode(2,INPUT_PULLUP);
}

void loop()
{
  int sensorVal = digitalRead(button);
  if (sensorVal == HIGH)
  {
    for (int i = 0; i < length; i++)
    {
      if (ttlsnotes[i] == ' ')
      {
        delay(ttlsbeats[i] * tempo);
      }
      else
        playNote(ttlsnotes[i], ttlsbeats[i] * tempo);

      if(digitalRead(button)==LOW) break;///小葉加這行(本來沒有按是HIGH,按下去變成LOW),可以卡歌...
      delay(tempo / 2);
    }
  }
  else
  {
    for (int i = 0; i < lengths; i++)
    {
      if (jbnotes[i] == ' ')
      {
        delay(jbbeats[i] * tempo);
      }
      else
        playNote(jbnotes[i], jbbeats[i] * tempo);
      delay(tempo / 2);
    }
  }
}












2018年11月15日 星期四

Week10 立欣ㄉ筆記

01.USB連接板子安裝CH341SER驅動程式





將arduino mega接上電腦安裝驅動程式

01.修改程式碼

新增球碰到球框會彈跳的程式


2018年10月25日 星期四

Week07 立欣的筆記

01.血量血條如何實作



當life<=0 show出Game Over

02.倒數計時如何實作

按1進入倒數畫面


倒數完按2 到遊戲結束畫面


遊戲結束











































2018年10月18日 星期四

Weeek06 立欣ㄉ筆記

01.加入聲音的資料庫







加入音檔

執行就播放音檔

02.水果人者



不斷重生