2019年1月20日 星期日

接雞蛋

float[] eggX=new float[100];
float[] eggY=new float[100];
boolean[] eggDie=new boolean[100];
void setup() {
  size(800,600);
  for (int i=0;i<100;i++) {
  eggX[i]=random(100,700);
  eggY[i]=-random(2000);
  eggDie[i]=false;
  }
}
void draw() {
  background(255);
  rect(mouseX-50,mouseY-25,100,50);
  for (int i=0;i<100;i++){
  if(eggDie[i])continue;
  ellipse(eggX[i],eggY[i],80,100);
  eggY[i]+=5;
  if(eggY[i]>700) eggY[i]=-2000+600;
  if( dist(mouseX-50,mouseY-25,eggX[i],eggY[i])<50){
    eggDie[i]=true;
    }
  }
}

}

week6_

1.放入音檔


(從文件裡找範例程序


(並選擇此程序



(複製這兩行程式碼


(丟入音檔即可撥放

AHSU interaction week 7

血條的做法(但是會扣到超過)









Week07劉峻宇

                                         上課實作

1.血量製作
int life=10;
boolean gameOver=false;
void setup(){
   size(500,500);
}
void draw(){
  background(0,0,205);
  fill(255); rect(50,50, 100,20);
  fill(255,0,0); rect(50,50, 100,20);
  if(gameOver){
    textSize(40);
    text("Game Over", 150,150);
  }
}
void mousePressed(){
  life--;
  if(life<=0) gameOver=true;
}



2.

2019年1月16日 星期三

Week12 李宜謙

一同去郊遊,去了 Hackerspace 做光劍去

我因為車子壞掉缺席,但後來我有去補做!
大家分工一起做了三隻光劍,超炫的一起耍中二

中二病


           禁止停車聽不懂??

小助手與我們


2019年1月12日 星期六

Week17-04160453


期末展示








https://www.youtube.com/watch?v=XAV36W_HuG4

Week16-04160453

今天寫除了飛機可以社子彈並允實落下,但是無法解決子但碰到允實讓允實消失,希望可以在廉假時解決這個問題

PImage imgplane, imgbg, imgs, imgS, imgfire;
float planeX=250, planeY=600;
float enemyX, enemyY, enemyVX, enemyVY;
float[] stoneX = new float[10000];
float[] stoneY = new float[10000];
float[] stone1X = new float[10000];
float[] stone1Y = new float[10000];
boolean[] stoneDie = new boolean[10000];
boolean[] stone1Die = new boolean[100];
/*
void reborn(int i){
   fireX[i]=mouseX-16;
   fireY[i]=mouseY-100;
   fireVY[i]=-20;
}
*/
void setup() {
  size(600, 800); 
  imgplane = loadImage("plane.png");
  imgbg = loadImage("bg.jpg");
  imgs = loadImage("stone1.png");

  imgfire = loadImage("fire.png");
  
  for(int i=0;i<100;i++){
    stoneX[i] = random(0,500);
    stoneY[i] =-random(2000);
    stoneDie[i] = false;
    stone1X[i] = random(0,500);
    stone1Y[i] =-random(2000);
    stone1Die[i] = false;
  }
}
void draw() {
  image(imgbg, 0, 0, width, height);
  image(imgplane, mouseX-40, mouseY-60, 80, 120);
  for(int i=0;i<fireN;i++){
     if(stoneDie[i])continue;
     image(imgs,stoneX[i],stoneY[i],70,70);
     stoneY[i]+=9;
     if(stoneY[i]>650) stoneY[i]=-2000+800;
     image(imgfire,fireX[i],fireY[i], 30, 60);
      fireY[i]+=fireVY[i];
      fireVY[i]-= 0.98;
     //if(dist(fireX-50,fireY-50,stoneX[i],stoneY[i])<30)
        //stoneDie[i]=true;
     
  }
 
}
float []fireX=new float[10000];
float []fireY=new float[10000];
float []fireVY=new float[10000];
boolean []fireFlying = new boolean[10000];
int fireN=0;
void mousePressed(){
   fireFlying[fireN]=true;
   fireX[fireN]=mouseX-16;
   fireY[fireN]=mouseY-100;
   fireVY[fireN]=-20;
   fireN++;
}

Week15-04160453

嘗試寫出飛機打隕石的遊戲



今天討論出了大概弄好背景和飛機

Week14-04160453

Arduino LED燈 閃爍

到此GitHub網址下載Bounce之程式
void setup()
{
    pinMode(13,OUTPUT); //設定Led為output
}

void loop()
{
    int value=analogRead(A0);
    digitalWrite(13,HIGH); //LED 閃爍
    delay(value);
    digitalWrite(13,LOW); 
    delay(value);
}

---------

程式如下:


int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}

2019年1月11日 星期五

week17劉峻宇

               

                                       期末作品

組員:劉峻宇、沈哲民

作品名稱:LED燈光秀

youtube: https://www.youtube.com/watch?v=n_WAQuJgAGM

我們主要是去買一些燈光的器材
還有一些LED的燈泡,我們來製作燈光秀,搭配程式碼來使燈泡發亮
再來是我們使用一首音樂,程式碼可以跟著音樂的節奏來閃燈泡

如何操作:只需要找一首適合的音樂
賣點是什麼:在派對上可以帶氣氛
困難點是什麼:偵測音樂節奏,以及接線的過程




Week15 昱霖的筆記

Processing

import processing.serial.*;
Serial duankou;
void setup() {
  size(500,500);
  duankou = new Serial(this, "COM3", 9600);
}
int X,a;
void draw() {
  getData();
  background(127);
  println(X);
  if(X<50&&X>0){
    delay(200);
    a+=1;
  ///  println(a);
  }
  fill(255,0,0);textSize(80);text("Score:"+a,100,100);
}
byte [] data=new byte[1];
void getData(){
   if (duankou.available() > 0) {
   duankou.readBytes(data);
   X=data[0];
   println(data);
  }
}

Week16 昱霖的筆記

Arduino

int photocellPin = 0; // 光敏電阻 (photocell) 接在 anallog pin 2
int photocellVal = 13; // photocell variable
int a=0;
void setup() {
  Serial.begin(9600);
  pinMode(photocellVal, OUTPUT);
}
byte data[1];
void loop() {
  // 讀取光敏電阻並輸出到 Serial Port
  photocellVal = analogRead(A0);
  //Serial.println(photocellVal);
  delay(200);   
  data[0]=photocellVal;
  Serial.write(data,1);
}

week16_鄭昕恬

我們的期末作品是電子鼓,雖然一開始就遇到許多瓶頸,但在老師的幫忙下我們終於慢慢有了頭緒,漸漸摸索出製作的過程,在程式碼上加以改進,處理的音樂延遲的問題。而原本想用焊接的方式,把電線跟用錫箔碗做成的鼓面結合,卻發現無法成功焊接上,所以就改成禪讓在鼓的邊緣,讓他們可以成功導電。這個期末作品,我們啜了很多測試,也參考了非常多的資料,但最後還是最感謝老師對我們的地不離不棄,認真地幫助所有同學做出很有成就感的期末作品,我覺得這堂課讓我受益良多。

附上YOUTUBE: https://youtu.be/KM31Ckis4po

2019年1月10日 星期四

week17 期末作品呈現

https://www.youtube.com/watch?v=SCsTUaNlIHM
期末呈現


week16 期末作品

仍在嘗試把滑鼠的輸入方式更改成類比搖桿

(https://www.youtube.com/watch?v=SCsTUaNlIHM)

week15 阮致峰

期末作品ing

week14 阮致峰

旋鈕


連接板子


開啟範例

(點選圖中網址可以連結到網站)

轉動旋鈕即可改變燈光閃爍頻率

week13 阮致峰

把arduino跟processing做連結

用processing裡面的範例
SimpleReadProcessing\file\example\libaries\serial\ SimpleRead


把程式碼複製貼到arduino



1. 在arduino裡把pinMode的INPUT改為PULLUP_INPUT
2. 把接腳改為2
3. Processing : new Serial的第二個參數改成連上的埠(ex:COM3)

week12 阮致峰

戶外教學(缺席)

week11 阮致峰

燈光閃爍
void setup() 
{
  for(int i=2 ; i<=13 ;i++)
    {
      pinMode(i,OUTPUT);
    }
}

void loop()
 {
  for(int i=2 ; i<13 ; i++)
     {
         digitalWrite(i , HIGH);
         delay(300);                                                                                                                                                             }
    for(int i=2 ; i<=13 ; i++)
     {
        digitalWrite(i,LOW);
      }
}  

播放音樂(小星星)
int piezoPin = 8;
int length = 15;
char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";
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);
  }
}

燈光跟著音樂閃動
int piezoPin = 8;
int length = 15;
char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc "; 
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)
{
  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()
{
  for(int i=2;i<=13;i++) pinMode(i,OUTPUT); ///第四行 在執行之前 把每個腳位 都設成OUTPUT 才會亮跟發聲音
  pinMode(2,INPUT_PULLUP);
}

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);
  }
}

week10 阮致峰

到官網下載驅動程式
https://makeruno.com.my/getting-started/?fbclid=IwAR0BbCC92god1fDsUUfDWVUTH_wFJ31RQz38n3PnoikAnDcpzCuo475fFGs

當安裝成功並接上板子,到裝置管理員查看
有出現表示安裝成功了

week09 阮致峰

week07 阮致峰

1.
int life=10;
boolean gameOver=false;
void setup()
{
  size(500,500);
}
void draw()
{
  background(0,0,205);
  fill(255); rect(50,50, 100,20);
  fill(255,0,0); rect(50,50, life*10,20);
  if(gameOver){
    textSize(40);
    text("Game Over",150,150);
  }
}
void mousePressed()
{
  life--;
  if(life<=0) gameOver=true;
}
血條

week06 阮致峰

1.
水果忍者
float fruitX, fruitY, fruitVX, fruitVY;
void setup()
{
  size(800,600);
   fruitX=30;  fruitVX=3;
  fruitY=700;  fruitVY=-35;
 }
void draw()
{
  background(0);
 ellipse(fruitX,fruitY,100,100);
  fruitX+=fruitVX;
  fruitY+=fruitVY;
  fruitVY+=0.98;
}


2.
很多水果的水果忍者
float [] fruitX=new float[20];
float [] fruitY=new float[20];
float [] fruitVX=new float[20];
float [] fruitVY=new float[20];
void setup()
{
  size(800,600);
  for(int i=0;i<20;i++){
  fruitX[i]=random(800);  fruitVX[i]=3;
  fruitY[i]=700;  fruitVY[i]=-35;
  }
}
void draw()
{
  background(0);
  for(int i=0;i<20;i++){
  ellipse(fruitX[i],fruitY[i],100,100);
  fruitX[i]+=fruitVX[i];
  fruitY[i]+=fruitVY[i];
  fruitVY[i]+=0.98;
  }
}


3.
可切水果
float [] fruitX=new float[20];
float [] fruitY=new float[20];
float [] fruitVX=new float[20];
float [] fruitVY=new float[20];
void reborn(int i){                                         
  fruitX[i]=random(800);  fruitVX[i]=(6)-3;
  fruitY[i]=700;  fruitVY[i]=-35;
}
void setup(){
  size(800,600);
  for(int i=0;i<20;i++){
    reborn(i);
  }
}
void draw(){
  background(0);
  for(int i=0;i<20;i++){
    if( dist(mouseX, mouseY, fruitX[i],fruitY[i])<=50){
      reborn(i); continue;
    }
    ellipse(fruitX[i],fruitY[i], 100,100);
    fruitX[i]+=fruitVX[i];
    fruitY[i]+=fruitVY[i];
    fruitVY[i]+=0.98;
    if(fruitY[i]>700) reborn(i);
  }
}

week10

下載Arduino IDE Software並且安裝CH341 Driver for Windows here


安裝完照老師說明的接上電腦後,要確認序列阜是com幾

Week15_05160664

Week15
將娃娃機的3D列印零件列印下來

 舵機轉2GT同步帶輪聯結器 *2(右邊)

X軸及同步帶固定零件
Z軸固定馬達及爪子的零件
 以下的是3D列印機的影片