int switchStateRed = 0; int switchStateBlue = 0; void setup(){ pinMode(2, INPUT); pinMode(3, INPUT); Serial.begin(9600); } int a=0,b=0; void loop(){ switchStateRed = digitalRead(2); switchStateBlue = digitalRead(3); if(switchStateRed == LOW) a=0; if(switchStateRed == HIGH && a==0) {Serial.write('a'); a=1;} if(switchStateBlue == LOW) b=0; if(switchStateBlue == HIGH && b==0) {Serial.write('b'); b=1;} }
2014年1月12日 星期日
期末作品
int switchStateRed = 0; int switchStateBlue = 0; void setup(){ pinMode(2, INPUT); pinMode(3, INPUT); Serial.begin(9600); } int a=0,b=0; void loop(){ switchStateRed = digitalRead(2); switchStateBlue = digitalRead(3); if(switchStateRed == LOW) a=0; if(switchStateRed == HIGH && a==0) {Serial.write('a'); a=1;} if(switchStateBlue == LOW) b=0; if(switchStateBlue == HIGH && b==0) {Serial.write('b'); b=1;} }
2013年12月22日 星期日
week16
import ddf.minim.*; Minim minim; AudioPlayer player; PImage imgbackground; import processing.serial.*; //!!!!!!!!!!!!!!!! Serial serial; //!!!!!!!!!!!!!!!! int []drumColor = new int [93]; int []drumX = new int[93]; int score =0; int x=600; void setup() { serial = new Serial(this, "COM3", 9600); //!!!!!!!!!!!!!!!! size(600, 400); imgbackground = loadImage("background.png"); for (int i=0;i<93;i++) { drumColor[i]=int(random(2)); drumX[i]=600+i*100; } minim = new Minim(this); player = minim.loadFile("m.mp3"); player.play(); } void draw() { char c=' '; //!!!!!!!!!!!!!!!! if (serial.available()>0) { //!!!!!!!!!!!!!!!! c = (char)serial.read(); //!!!!!!!!!!!!!!!! print(c); } //image(imgbackground, 0, 0); background(imgbackground); fill(255); ellipse(135, 137.5, 38, 38); for (int i=0;i<93;i++) { if (drumX[i]-135<30 && drumX[i]-135>-30) { if (c == 'a' && drumColor[i]==0) { //!!!!!!!!!!!!!!!! score++; println("分數:"+score); } else if (c == 'b' && drumColor[i]==1) { //!!!!!!!!!!!!!!!! score++; println("分數:"+score); } fill(0, 255, 0); ellipse(drumX[i], 137.5, 36, 36); drumX[i]-=2; } else if (drumColor[i]==0) { fill(255, 0, 0); ellipse(drumX[i], 137.5, 36, 36); drumX[i]-=2; } else if (drumColor[i]==1) { fill(0, 0, 255); ellipse(drumX[i], 137.5, 36, 36); drumX[i]-=2; } } fill(0); textFont(createFont("calibri", 40)); textSize(30); text("score : "+score, 230, 300); }
2013年12月16日 星期一
week15
int switchStateRed = 0;
int switchStateBlue = 0;
void setup(){
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
}
int a=0,b=0;
void loop(){
switchStateRed = digitalRead(2);
switchStateBlue = digitalRead(3);
if(switchStateRed == LOW) a=0;
if(switchStateRed ==HIGH&& a==0) {Serial.write('a'); a=1;}
if(switchStateBlue ==LOW) b=0;
if(switchStateBlue==HIGH&& b==0) {Serial.write('b'); b=1;}
}
下周預備套用在鼓的上面~~
2013年12月8日 星期日
2013年12月1日 星期日
week13
project5
#include <Servo.h> Servo myServo; int const potPin = A0; int potVal; int angle; void setup(){ myServo.attach(9); Serial.begin(9600); } void loop(){ potVal = analogRead(potPin); Serial.print("potVal"); Serial.print(potVal); angle = map(potVal, 0, 1023, 0, 179); Serial.print(", angle: "); Serial.println(angle); myServo.write(angle); delay(15); }
project6
int sensorValue; int sensorLow = 1023; int sensorHigh = 0; const int ledPin = 13; void setup(){ pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); while(millis()<5000){ sensorValue = analogRead(A0); if(sensorValue > sensorHigh){ sensorHigh = sensorValue; } if(sensorValue < sensorLow){ sensorLow = sensorValue; } } digitalWrite(ledPin, LOW); } void loop(){ sensorValue = analogRead(A0); int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); tone(8, pitch, 20); delay(10); }
project7
int notes[] = {262, 294, 330, 349}; void setup(){ Serial.begin(9600); } void loop(){ int keyVal = analogRead(A0); Serial.println(keyVal); if(keyVal == 1023){ tone(8, notes[0]); } else if(keyVal >= 990 && keyVal <= 1010){ tone(8, notes[1]); } else if(keyVal >= 505 && keyVal <= 515){ tone(8, notes[2]); } else if(keyVal >= 5 && keyVal <= 10){ tone(8, notes[3]); } else{ noTone(8); } }
2013年11月24日 星期日
week12
project 3
const int sensorPin = A0; const float baselineTemp = 20.0; void setup(){ Serial.begin(9600); for(int pinNumber = 2; pinNumber<5; pinNumber++){ pinMode(pinNumber,OUTPUT); digitalWrite(pinNumber, LOW); } } void loop(){ int sensorVal = analogRead(sensorPin); Serial.print("Sensor Value:"); Serial.print(sensorVal); float voltage = (sensorVal/1024.0)*5.0; Serial.print(", Volts:"); Serial.print(voltage); Serial.print(", degrees C:"); float temperature = (voltage - .5)*100; Serial.println(temperature); if(temperature < baselineTemp){ digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); } else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){ digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); } else if(temperature >= baselineTemp+6){ digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); } delay(1); }
project 4
const int greenLEDPin = 9; const int redLEDPin = 10; const int blueLEDPin = 11; const int redSensorPin = A0; const int greenSensorPin = A1; const int blueSensorPin = A2; int redValue = 0; int greenValue = 0; int blueValue = 0; int redSensorValue = 0; int greenSensorValue = 0; int blueSensorValue = 0; void setup(){ Serial.begin(9600); pinMode(greenLEDPin,OUTPUT); pinMode(redLEDPin,OUTPUT); pinMode(blueLEDPin,OUTPUT); } void loop(){ redSensorValue = analogRead(redSensorPin); delay(5); greenSensorValue = analogRead(greenSensorPin); delay(5); blueSensorValue = analogRead(blueSensorPin); Serial.print("Raw Sensor Values \t Red"); Serial.print(redSensorValue); Serial.print("\t Green:"); Serial.print(greenSensorValue); Serial.print("\t Blue:"); Serial.print(blueSensorValue); redValue = redSensorValue/4; greenValue = greenSensorValue/4; blueValue = blueSensorValue/4; Serial.print("Mapped Sensor Values \t Red:"); Serial.print(redValue); Serial.print("\t Green:"); Serial.print(greenValue); Serial.print("\t Blue:"); Serial.print(blueValue); analogWrite(redLEDPin, redValue); analogWrite(greenLEDPin, greenValue); analogWrite(blueLEDPin, blueValue); }
2013年11月17日 星期日
期中作品-太鼓達人
import ddf.minim.*;
Minim minim;
AudioPlayer player;
PImage imgbackground;
int []drumColor = new int [93];
int []drumX = new int[93];
int score =0;
int x=600;
void setup() {
size(600,400);
imgbackground = loadImage("background.png");
for (int i=0;i<93;i++) {
drumColor[i]=int(random(2));
drumX[i]=600+i*100;
}
minim = new Minim(this);
player = minim.loadFile("m.mp3");
player.play();
}
void draw() {
//image(imgbackground, 0, 0);
background(imgbackground);
fill(255);
ellipse(135, 137.5, 38, 38);
for (int i=0;i<93;i++) {
if (drumX[i]-135<3 && drumX[i]-135>-3) {
if (keyPressed && key=='z' && drumColor[i]==0) {
score++;
println("分數:"+score);
minim = new Minim(this);
player = minim.loadFile("f.mp3");
player.play();
}
else if (keyPressed && key=='x'&& drumColor[i]==1) {
score++;
println("分數:"+score);
minim = new Minim(this);
player = minim.loadFile("f.mp3");
player.play();
}
fill(0, 255, 0);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
else if (drumColor[i]==0) {
fill(255, 0, 0);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
else if (drumColor[i]==1) {
fill(0, 0, 255);
ellipse(drumX[i], 137.5, 36, 36);
drumX[i]-=2;
}
}
fill(0);
textFont(createFont("calibri",40));
textSize(30);
text("score : "+score, 230, 300);
}
2013年11月10日 星期日
2013年10月28日 星期一
week08
遊戲名稱:太鼓達人
遊戲玩法:當紅色或藍色的圓圈跑到指定的白色圓圈中時,會變成綠色
當按下指定的按鈕(藍色"x",紅色"y")獲取分數,
跟著節奏訓練自己的手眼協調力,也可以在好聽的歌曲中加入自己的鼓聲
使遊戲更好玩。
和楊舒婷一起做
2013年10月13日 星期日
week06
float [] ballX=new float[50], ballY=new float[50];
float [] ballVX=new float[50], ballVY=new float[50];
int top=0;
int flightX=300, flightY=300, S=20;
PImage imgBall;
PImage imgFire;
void setup() {
size(600, 600);
imgBall=loadImage("http://images1.wikia.nocookie.net/__cb20120311052422/elderscrolls/images/thumb/1/10/MAGINVFireballArt.png/250px-MAGINVFireballArt.png");
for (int i=0;i<50;i++) {
newBall(i);
}
}
int bad=0;
void draw() {
if (bad==1) {
background(255, 0, 0);
for (int i=0;i<50;i++) {
ballVX[i]=0;
ballVY[i]=0;
}
}
else background(0);
for (int i=0;i<50;i++) {
triangle(flightX,flightY,flightX-S/2,flightY+S,flightX+S/2,flightY+S);
image(imgBall,ballX[i],ballY[i],S*1.5,S*1.5);
ballX[i]+=ballVX[i]; ballY[i]+=ballVY[i];
if (ballX[i]<0 || ballX[i]>600 || ballY[i]<0 || ballY[i]>600) newBall(i);
if (dist(ballX[i], ballY[i], flightX, flightY)<S)bad=1;
}
}
void newBall(int i) {
float angle =random(2*PI);
ballVX[i]=cos(angle);
ballVY[i]=sin(angle);
int dir=int (random(4));
if (dir==0) {
ballX[i]=random(600);
ballY[i]=0;
}
else if (dir==1) {
ballX[i]=random(600);
ballY[i]=600;
}
else if (dir==2) {
ballX[i]=0;
ballY[i]=random(600);
}
else if (dir==3) {
ballX[i]=600;
ballY[i]=random(600);
}
}
void mouseMoved(){
flightX=mouseX;
flightY=mouseY;
}
2013年10月6日 星期日
2013年9月29日 星期日
week04
void setup(){
size(400,400);
background(255);
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
}
void draw(){
}
void mouseDragged(){
line(mouseX,mouseY,pmouseX,pmouseY);
}
void mousePressed(){
if(mouseX<100&&mouseY<100){
colorMode(HSB,100);
stroke(mouseX,mouseY,100);
}
else if(mouseX<100&&mouseY<200){
colorMode(RGB,255);
stroke(143,245,232);
}
}
void setup() {
size(500, 500);
background(255);
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
fill(255);
rect(400,0,100,100);
strokeWeight(10);
stroke(#000000);
point(450,50);
}
void draw() {
}
void mouseDragged() {
if(mouseX>100) line(mouseX, mouseY, pmouseX, pmouseY);
}
void mousePressed() {
if (mouseX<100&&mouseY<100) {
colorMode(HSB, 100);
stroke(mouseX, mouseY, 100);
}
else if(mouseX<100&&mouseY<200){
stroke(#8FF5E8);
}
}
2013年9月22日 星期日
Week03

1. 今天目標: 畫出一個五子棋
1.1. 使用 Tool- Color Selector, 挑出你要的顏色, 可用 R,G,B 來描述,也可用 #0B33FF 之類的像亂碼的數字來設定顏色
1.2. 要畫外框,可以用 rect()來畫, 要修改填充的顏色可以用fill(), 要讓畫的內部不要填充, 可以查看 Help-Reference 後,在 fill()樓上樓下相關的地方找到你要的功能 (ex. noFill() )
1.3. 使用 stroke() 來調畫線stroke的顏色, 在 Help-Reference 裡面可以找 stroke 相關的功能,像是比較粗的 stroke 可以用 strokeWeight() 來設定權重粗細
1.4. 想要畫裡面的細黑線,可以用 line() 來畫,配上不同的 strokeWeight() 粗細
1. Google 美女工程師, 程式語言用 Ruby, C++, Processing
1.1. TODO: 請去找一下 Processing 寫出來的作品
1.2. TODO: 用 Youtube 分享,按Blogger 把 HTML的 <iframe...> 貼在你的作業中
1.3. 下載 Processing
2. TODO: 寫出你的第一個Processing 程式碼: Hello World 變 Hello Kitty
3. TODO: 請找一張圖,用小畫家(mspaint)輔佐你,畫出你的 Processing 圖, 並都貼出來。
4. TODO: 請寫下你的心得 (1) 你學了什麼東西, (2) 有什麼東西不懂, (3) , 還想學什麼
這次的上課感覺比較快,有些東西需要思考才比較可以想清楚程式的運作,雖然這次應該有把大部分的程式搞懂,在array的地方希望老師在幫我們加強,因為那邊很不熟,謝謝老師。
貼你覺得有意思的影片, 使用youtube 的分享, Blogger 分享, 兩邊都改成 HTML, 貼上
HTML
2013年9月15日 星期日
Week02
1. Processing 啟動, 有問題的同學請再下載download
http://processing.org
2. 試 for迴圈
3. 試用 Processing-Help-Reference
3.1. 找 rect() 函式
3.2. 看看 rect() 樓上樓下的相關函式, 並嘗試畫出和老師不同的圖 [課堂作業1]
4. 那想要改變顏色呢?
4.1. fill() 是填充的顏色, stroke()是筆的顏色
4.2. 透明的顏色(alpha),其實也是顏色(color)
5. 加一點點滑鼠的互動吧! 可以使用 mouseX 及 mouseY 的值,來進行色彩繽紛的運算
6. 亂數 random(數字上界) 來設定初始的亂數值 [課堂作業3] 利用mouseX,mouseY,random()做設計
[課堂作業4] 請大家寫一下到現在的心得 (ex. 速度, 內容, 想學的東西, 期待、希望、夢想..)
http://processing.org
2. 試 for迴圈
3. 試用 Processing-Help-Reference
3.1. 找 rect() 函式
3.2. 看看 rect() 樓上樓下的相關函式, 並嘗試畫出和老師不同的圖 [課堂作業1]
4. 那想要改變顏色呢?
4.1. fill() 是填充的顏色, stroke()是筆的顏色
4.2. 透明的顏色(alpha),其實也是顏色(color)
5. 加一點點滑鼠的互動吧! 可以使用 mouseX 及 mouseY 的值,來進行色彩繽紛的運算
6. 亂數 random(數字上界) 來設定初始的亂數值 [課堂作業3] 利用mouseX,mouseY,random()做設計
2013年9月8日 星期日
Week01
0. 課程準備
0.1. 加入 課程FB社團
0.2. Google文件 填寫修課資料 (學號姓名,email,電話)
0.3. 加入 Blog, 設定
編交作業方式: tag: 000葉正聖老師, Week01, 00160011葉大明
逗號隔開, 學號姓名間不要有空格
1. 看一下去年學長姐們做的成果 (划船、吃角子老虎、數位手套、直昇機控制搖桿), 聖誔老公公下樓梯
2. 試著執行 Processing
size(600,600);
background(255, 0, 0);
rect(100,100, 200,200);//貼在左上方來100,100的位置,貼成200,200的方型
第二節課的範例
可以看一下老師做的 Angry Birds Brick
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/
size(600,600);
background(255, 0, 0);
rect(100,100, 200,200);
PImage imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
PImage imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
image(imgBird, 0,0);
image(imgPig, 200,200, 100,100);
第三節課的範例
PImage imgBird, imgPig;
void setup() {
size(600, 600);
imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
imageMode(CENTER);
}
void draw() {
background(255, 0, 0);
image(imgBird, mouseX, mouseY);
image(imgPig, 200, 200, 100, 100);
}
https://class.coursera.org/digitalmedia-001/lecture/index
0.1. 加入 課程FB社團
0.2. Google文件 填寫修課資料 (學號姓名,email,電話)
0.3. 加入 Blog, 設定
編交作業方式: tag: 000葉正聖老師, Week01, 00160011葉大明
逗號隔開, 學號姓名間不要有空格
1. 看一下去年學長姐們做的成果 (划船、吃角子老虎、數位手套、直昇機控制搖桿), 聖誔老公公下樓梯
2. 試著執行 Processing
size(600,600);
background(255, 0, 0);
rect(100,100, 200,200);//貼在左上方來100,100的位置,貼成200,200的方型
第二節課的範例
可以看一下老師做的 Angry Birds Brick
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/
size(600,600);
background(255, 0, 0);
rect(100,100, 200,200);
PImage imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
PImage imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
image(imgBird, 0,0);
image(imgPig, 200,200, 100,100);
第三節課的範例
PImage imgBird, imgPig;
void setup() {
size(600, 600);
imgBird=loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/bird.png");
imgPig =loadImage("http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/pig.gif");
imageMode(CENTER);
}
void draw() {
background(255, 0, 0);
image(imgBird, mouseX, mouseY);
image(imgPig, 200, 200, 100, 100);
}
https://class.coursera.org/digitalmedia-001/lecture/index
訂閱:
文章 (Atom)





























