顯示具有 05161102_沈哲民 標籤的文章。 顯示所有文章
顯示具有 05161102_沈哲民 標籤的文章。 顯示所有文章

2019年1月8日 星期二

Week12_沈哲民

Arduino

---------------------

// Wiring / Arduino Code
// Code for sensing a switch status and writing the value to the serial port.

int switchPin = 2;                       // Switch connected to pin 4

void setup() {
  pinMode(2,INPUT_PULLUP);             // Set pin 0 as an input
  Serial.begin(9600);                    // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(2) == HIGH) {  // If switch is ON,
    Serial.write(1);               // send 1 to Processing
  } else {                               // If the switch is not ON,
    Serial.write(0);               // send 0 to Processing
  }
  delay(100);                            // Wait 100 milliseconds
}

------------------------------

Processing

------------------------------

/**
 * Simple Read
 *
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM7", 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  background(255);             // Set background to white
  if (val == 0) {              // If the serial value is 0,
    fill(0);                   // set fill to black
  }
  else {                       // If the serial value is not 0,
    fill(204);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}

---------------------------------

注意事項:

1.Processing 範例檔 Simple Read
2.先讓板子執行再跑Processing
3.注意反白記號要改的部分


2019年1月3日 星期四

WeeK17_沈哲民




10_LED strip_沈哲民05161102、05163082劉俊宇.zip




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

說明你做了什麼:材料準備、接線材、程式尋找
如何操作:只需要找一首適合的音樂
賣點是什麼:在派對上可以帶動派對的氣氛、也可以做一些燈光show。
困難點是什麼:偵測音樂節奏,以及接線的過程!

2018年12月27日 星期四

Week16_沈哲民

期末作品製作:



材料備齊,線材也接上了,led燈調也順利亮了,也有透過簡單的小程式去做和processing 及 arduino去做互動,接下來的步驟就是如何 輸入音樂趣讓程式偵測及傳送的arduino 作互動

Week15_沈哲民

製作期末作品

一開始我們還在搜尋接LED strip到 maker uno的板子,需要什麼材料,需要怎麼接,後來發現不是這麼的容易,需要電晶體、電阻、變壓器這些東西才可以完全接上並發光。

而之中我也了解到電晶體也有分、LED 燈調也有分...

2018年12月6日 星期四

Week13 _沈哲民

安裝驅動程式(驅動maker uno)





注意

1. Maker uno 的模式
2.  連接com7 !




processing 和 arduino 互動

打開processing ---> 文件 ------> 範例程序 -------> Serial ------> SimpleRead



製到Arduino
將腳位改成pin2

**程式碼:
int switchPin = 4;                       // Switch connected to pin 4

void setup() {
  pinMode(switchPin, INPUT);             // Set pin 0 as an input
  Serial.begin(9600);                    // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(switchPin) == HIGH) {  // If switch is ON,
    Serial.write(1);               // send 1 to Processing
  } else {                               // If the switch is not ON,
    Serial.write(0);               // send 0 to Processing
  }
  delay(100);                            // Wait 100 milliseconds




記住 processing 要改成com7



2018年11月22日 星期四

Week11_沈哲民

1.如何播歌、切歌


.





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)
{
  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);
  pinMode(button, 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);
      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月1日 星期四

Week08劉峻宇

                                 期中作品分享

第17組
組員:劉峻宇&沈哲民

遊戲名稱:打靶射擊

玩法規則:
先點擊鍵盤數字1
開始遊戲

使用滑鼠來描準來射擊隕石,限時一分鐘內,擊落的隕石越多,分數越高
分數超過每一個關卡的門檻分數就過關。

網址:https://www.youtube.com/watch?v=-7iACwebJsw

2018年10月18日 星期四

WEEK06_沈哲民

import-音樂

速寫本-引用文件庫-添加文件庫-sound-(1)Sound|Provides... (2)Minim....

程式碼:
import ddf.minim.*;
Minim minim; //宣告
AudioPlayer player; //宣告 player
void setup()
{
  minim= new Minim(this);
  player=minim.loadFile("Kalimba.mp3");
  player.play();
}
void draw()
{
  
}


切水果遊戲:

float []fruitX=new float[20];  //宣告位置x
float []fruitY=new float[20];  //宣告位置y
float []fruitVX=new float[20];  //宣告位置x速度
float []fruitVY=new float[20]; // 宣告位置y速度

void reborn(int i)///重生水果
{
   fruitX[i]=random(500); fruitVX[i]=random(3);
  fruitY[i]=700; fruitVY[i]=random(-45);
}

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 && fruitX[i]>900) reborn(i); //如果x的位置超出 或 y的位置超出 重生
  }
}

2018年10月11日 星期四

2018年10月4日 星期四

Week04_沈哲民




void setup(){


  size(800,600);

}

void draw(){

  fill(0,102,153,51); text("star!",100,100);
 
  textSize(60);

  fill(250,0,250);rect(101,101,200,200);

}

fill(0,0,0)填色
text("...") 文字
textSize(60) 文字大小

-------------









void setup(){

  size(800,600);


}

void draw(){
 
  background(255);
 

  if(bulletFlying){
   
    ellipse(bulletX,bulletY,50,50);fill(250,0,0);
   
    bulletX+=3;
 
  }//函式判斷

}
float bulletX=500,bulletY=100;
boolean bulletFlying=false;//函式判斷

void keyPressed(){

  bulletFlying=true;//函式判斷
 
}

我們用函式判斷,bulletFlying一開始判斷為 false(0)
按下按鍵後 就變為true(1)
if函式 讓圓的位置 +3....

----------多顆子彈-------


for(int i=0;i<bulletN;i++)
 {
  if(bulletFlying[i])
  {
    ellipse(bulletX[i],bulletY[i],50,50);
    bulletX[i]+=3;
  }
 }
}
float []bulletX=new float[100]; 第N顆子彈的X座標
float []bulletY=new float[100]; 第N顆子彈的Y座標
int bulletN=0;//第幾顆子彈
boolean []bulletFlying= new boolean[100];

void keyPressed(){

  bulletFlying[bulletN]=true;
  bulletX[bulletN]=100;
  bulletY[bulletN]=100;
  bulletN++;
}

------------------------------------------
PImage Bg,bullet;//圖片宣告
void setup()
{
  size(800,600);
  Bg= loadImage("disert.jpg");//將圖片拉入程式及可放入程式資料夾
  bullet= loadImage("bullet.png");
  imageMode(CENTER);
}
void draw()
{
  image(Bg,width/2,height/2,width,height);
  image(bullet,mouseX,mouseY,100,100);
}

-------------------------圖片+子彈移動-----------------




PImage Bg,bullet;
void setup()
{
  size(800,600);
  Bg= loadImage("disert.jpg");
  bullet= loadImage("bullet.png");
  imageMode(CENTER);
}
void draw()
{
  image(Bg,width/2,height/2,width,height);
  image(bullet,mouseX,mouseY,100,100);
  for(int i=0;i<bulletN;i++)
  {
    if(bulletFlying[i]){
      image(bullet,bulletX[i],bulletY[i],100,100);
      bulletX[i]+=3;
    }

  }
 
}
float []bulletX= new float[100];
float []bulletY= new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void mousePressed()
{
  bulletFlying[bulletN]=true;
  bulletX[bulletN]=mouseX;
  bulletY[bulletN]=mouseY;
  bulletN++;
 
 
}
------------向上然後下墜--------
PImage Bg,bullet;
void setup()
{
  size(800,600);
  Bg= loadImage("disert.jpg");
  bullet= loadImage("bullet.png");
  imageMode(CENTER);
}
void draw()
{
  image(Bg,width/2,height/2,width,height);
  image(bullet,mouseX,mouseY,100,100);
  for(int i=0;i<bulletN;i++)
  {
    if(bulletFlying[i]){
      image(bullet,bulletX[i],bulletY[i],100,100);
      bulletY[i]+=bulletVY[i];
      bulletVY[i]+=0.98;
    }

  }
 
}
float []bulletX= new float[100];
float []bulletY= new float[100];
float []bulletVY= new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void mousePressed()
{
  bulletFlying[bulletN]=true;
  bulletX[bulletN]=mouseX;
  bulletY[bulletN]=mouseY;
  bulletVY[bulletN]=-20;
  bulletN++;
 
 
}





2018年9月20日 星期四

Week02

Week02上課內容

void setup(){}
void draw(){}

ellipse(位置x,位置y,大小x,大小y);//畫圓;

圓會隨著滑鼠移動,半徑會每秒-1的作變化


void setup()
{
   colorMode(HSB,100); // H,S,B都設100
}

int H=50;//用H去改顏色
void draw()
{
   彩色效果;
  往四面八方移動
}

彩色效果
fill(r,g,b) 填滿色彩
fill(H,100,100);
H++;
if(H==100)  H=50;



往四面八方移動


圖片放入

找圖片存入(速寫本-打開程序目錄)

Pimage img//圖片的宣告

void setup(){}
img=loadImage(".........jpg");//圖片讀入

void draw(){}
image(img,mouseX,mouseY,100,100);


background背景色

Week01

Week01上課內容
--------------------------
void setup(){
  size(800,600);
  line(0,0,100,100);
  rect(100,100,600,400);
}
void draw(){

}


-----------------------------------
mousePressed 滑鼠壓下去的時候
line 畫線;
rect (位置x,位置y,大小x,大小y);
size 視窗大小;
pmouseX 滑鼠x一開始的位置
mouseX 滑鼠x 現在的位置

-----------------------------------