顯示具有 05161145_洪毓謙 標籤的文章。 顯示所有文章
顯示具有 05161145_洪毓謙 標籤的文章。 顯示所有文章

2018年12月13日 星期四

Week14 1000



程式碼(控制滑鼠的座標位置)

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

Week13 1000

Week12 1000

HakerSpace 製作光劍
1.先準備110顆LED燈
2.將燈變成ㄇ字型
3.正接正負接負 用焊槍焊接起來
4.成功焊接完所有LED燈泡後 將燈條塞入燈管
5.焊上電阻還有可充電電池
6.裝上光劍握把
7.完!成

大家都做得蠻用心的 因為需要很多耐心才可以完成
真的也很謝謝老師贊助我們大家做光劍!

Week11 1000

燈光連續閃爍

void setup() {
  // put your setup code here, to run once:
  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 ";      // 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);
  }
}

音符跟著燈一起閃爍

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)

{
  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);
  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 1000

官網:
https://makeruno.com.my/getting-started/

範例1:
https://makeruno.com.my/changing-melody-with-push-button-using-only-maker-uno/?fbclid=IwAR3toK_dzBpVnaznTVoDUP1ypCe-BlyLQ1TL4ETyyYN2s7VteRzSLZd8fcM

範例2:
https://www.arduino.cc/en/Tutorial/Melody?fbclid=IwAR0bOhxFlcWHk7emOjChySiILAMaE-7DPcaq_BYjsQCcE6N7upLtnhhBUt8

Week09 1000

Week08 1000

期中作品分享

https://www.youtube.com/watch?v=2RBTzvxjX2s

2018年10月25日 星期四

Week07 1000





float pika1X=100,pika1Y=300, pika1VX=0,pika1VY=0;
void setup(){
  size(600,400);
}
void draw(){
  background(100,100,255);
  fill(255,255,0); ellipse(pika1X,pika1Y, 60,90);
  pika1X+=pika1VX;
}
void keyPressed(){
  if(keyCode==LEFT) pika1VX= -2;
  if(keyCode==RIGHT) pika1VX= +2;
}
void keyReleased(){
  if(keyCode==LEFT)  pika1VX= 0;
  if(keyCode==RIGHT) pika1VX= 0;
}


2018年10月18日 星期四

Week06 1000

聲音
gimport ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup(){
  minim = new Minim(this);
  player=minim.loadFile("groove.mp3");
  player.play();
}
void draw(){
}

跳出球球
很多球球











2018年10月11日 星期四

Week05 1000

複習上週

櫻桃程式碼
PImage img;
float[] cherryX=0, cherryY=700;
float[] cherryVX=6, cherryVY=-40;
void setup(){
   sixe(800,600)
   img=loadImage("cherry.png");
}
void draw(){
   background(255);
   img(img, cherryX, cherryY, 100,150);
   cherryX += cherryVX;
   cherryY += cherryVY;
   cherryVY += 0.98
}
   
   

Week03 1000

畫圈圈

2018年10月4日 星期四

Week04 1000




文字大小改變

發射子彈

發射連續子彈

void setup(){
    size(800,600);
}
void draw(){
  background(255);
  fill(255,0,0); rect(100,100,100,100);
  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];
float []bulletY= new float[100];
int bulletN=0;
boolean []bulletFlying= new boolean[100];
void keyPressed(){
  bulletFlying[ bulletN ] = true;
  bulletX[ bulletN ] = 100; bulletY[ bulletN ] =100;
  bulletN++;
}




2018年9月20日 星期四

Week02 1000

教 Generative Art (很多線,畫出網子)
看別人的成果
https://www.openprocessing.org/






void setup(){
  size(400,400);
  colorMode(HSB,100);
}
int R=50,H=0;
int Circlex=200,CircleY=200;
void draw(){
  fill(H,100,100);
  ellipse(CircleX,CircleY, R,R);
  R-=2;
  CircleX+=random(30)-15;
  CircleY+=random(30)-15;
  if(R<0){
    R=50;
    CircleX=200;CircleY=200;
  }
  H++;
 if(H>=100) H=0;
}




void setup(){
   size(800,600);
}
void draw(){
    if(mousePressed) line(mouseX,mouseY,pmouseX, pmouseY);
}
void keyPressed(){
   if(key=='1') strokeWeight(1);
   if(key=='2') strokeWeight(2);
   if(key=='1') strokeWeight(9);
}