顯示具有 Week13 標籤的文章。 顯示所有文章
顯示具有 Week13 標籤的文章。 顯示所有文章

2013年12月15日 星期日

Week13魏正

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

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

Project07
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年12月8日 星期日

week13

project 06: Light Theremin





















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 : Keyboard Instrument




















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年12月2日 星期一

week13

##Project 6 : Light Theremin



##程式碼
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); }


##Project 7 : Keyboard Instrument

Test1

Test2


##程式碼

int buttons[6]={2}; 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); } }

##Project 5 : Mood Cue

Test1


Test2


##程式碼
#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.print(angle); Serial.print("\n"); myServo.write(angle); delay(15); }

2013年12月1日 星期日

第十三周上課內容

1.project 06 Light Theremin

2.project 07 Keyboard Instrument

3.Mood Cue

WEEK13




譚庚倫的第13週作業

                                                                             馬達轉轉
程式碼:
#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); }


                                                                   聲音
程式碼:
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); }

                                                                          do re mi
程式碼:
int buttons [6];
 int notes[]={262,294,330,349};
void setup()
{
  Serial.begin(9600);
  buttons[0]=2;
}
void loop()
{
  int keyVal=analogRead(A0);
  Serial.println(keyVal);
  if(keyVal==1023)
  {
    tone(8,notes[0]);
  }
  else if(keyVal >=800&&keyVal<=930)
  {
    tone(8,notes[1]);
  }
  else if(keyVal>=100&&keyVal<=1200)
  {
    tone(8,notes[2]);

  }
  else if(keyVal>=400&&keyVal<=550)
  {
    tone(8,notes[3]);
  }
  else{
    noTone(8);
  }
}


第十三週作業

Project 5
void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); //程式一開始的五秒內是校正用的,這時候要趕快遮住/打開光敏電阻,讓程式修正最大和最小值 while (millis() < 5000) { sensorValue = analogRead(A0); if (sensorValue > sensorHigh) { sensorHigh = sensorValue; } if (sensorValue < sensorLow) { sensorLow = sensorValue; } } //等到燈熄滅,就開始進入 loop digitalWrite(ledPin, LOW); } void loop() { sensorValue = analogRead(A0); //這裡也使用了 map 函示來對應最高和最低的數值,對應為 50~4000 hz int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); tone(8, pitch, 20); delay(10); } #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); //這裡的 map function 可以把 0~1023 轉換到 0~179度 //很方便的函示 angle=map(potVal, 0, 1023, 0, 179); Serial.print(", angle: "); Serial.print(angle); myServo.write(angle); delay(15); }
Project 6
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;
    }
  }
  //等到燈熄滅,就開始進入 loop
  digitalWrite(ledPin, LOW);
}

void loop() {
  sensorValue = analogRead(A0);
  //這裡也使用了 map 函示來對應最高和最低的數值,對應為 50~4000 hz
  int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
  tone(8, pitch, 20);
  delay(10);
}
Project 7
int buttons[6];
int notes[]={262,294,330,349};
void setup(){
buttons[0]=2;
 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 >= 950 && keyVal <= 980){
tone(8,notes[3]);
}
else{
noTone(8);
}
}

Week13 作業

1. MOOD CUE :
#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); }


2. LIGHT THEREMIN :
int sensorValue; int sensorLow = 1023; int sensorHigh = 0; const int ledPin = 13; void setup() { // put your setup code here, to run once: 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() { // put your main code here, to run repeatedly: sensorValue = analogRead(A0); int pitch = map(sensorValue,sensorLow,sensorHigh, 50,4000); tone(8,pitch,20); delay(10); }


3. KEYBOARD INSTRUMENT :
int buttons[6]; int buttons[0] = 2;
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); } }

第十三週上課作業

1.旋轉馬達:
#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);
}




2.發出平率:
int sensorValue;
int sensorHigh=0;
int sensorLow=1023;

const int ledPin=23;
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,40000);
tone(8,pitch,440);
delay(10);
}




3. DO RE MI 聲
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);
 }
}

第十三 週上課作業

一, 旋轉馬達

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




二, 發出音頻

int sensorValue;
int sensorHigh=0;
int sensorLow=1023;const int ledPin=23;
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,40000);
tone(8,pitch,440);
delay(10);
}




三, 發出 Do Re Mi

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



week13

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){ sensorValue = sensorLow; } } digitalWrite(ledPin, LOW); } void loop(){ sensorValue = analogRead(A0); int pitch = map(sensorValue,sensorLow,sensorHigh, 50, 4000); tone(8,pitch,20); delay(10); }

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


=================================================================

第十三週上課內容

Project 05 (Mood Cue)

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



Project 06 (Light Theremin)

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



Project 07 (keyboard Instrament) 

Week13

05.Mood Cue
#include <Servo.h>

Servo myServo;

const int potPin = A0;
int potVal;
int angle;
void setup(){
  myServo.attach(9);
  Serial.begin(9600);
}
void loop(){
  potVal = analogRead(potPin);
  Serial.print("potVal:");
  Serial.println(potVal);
  angle = map(potVal , 0 , 1023, 0, 179);
  Serial.print(", angle:");
  Serial.println(angle);
  myServo.write(angle);
  delay(15);
}




06. Light Theremin
int sensorValue;
int sensorLow=1023;
int sensorHigh=0;
const int ledPin = 13;
void setup(){
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  while(millis() < 50000){
    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);
}



07. Keyboard Instrument
int buttons[6];

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 >= 900 && 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);
  }
}

Week13 葉玉婷

05 MOOD CUE

會隨著轉動的幅度而有不同的表現!!
程式碼

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


照片


影片






06 LIGHT THEREMIN

會依照感光而改變發出的聲音!!
程式碼

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


照片


影片



07 KEYBOARD INSTRUMENT

會依據按下的按鈕發出不同的聲音!!
程式碼
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);
    }
}

按下不同按鈕  值皆不同
也會發出不同的聲音






照片


影片

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

13周

提醒同學們,明天12/2(一) 是我們互動技術概論第13週的上課。
(1) 請不要忘了帶 Arduino Starter Kit 的實驗設備到學校哦!
(2) 明大要上課的內容是 Project 05 06 07 哦! 同學們今晚可以預習一下。
(3) 我們上課的目的,是為了讓同學們在期末完成自己構思的創意作品,同學們可以邊上課邊思考哦!
(4) 明天同學們記得帶 9V 的方塊電池(25元-60元一顆), 還有找找家裡有沒有一些要用電池的廉價的玩具, 我們可以在學校享受動手改裝的樂趣!


project5
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 buttons[6]; //int buttons[0] = 2; 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); } }

//影片


WEEK13 廖中遠








int buttons[6];

int notes[]={523.25,587.33,659.26,698.46};
void setup(){
  Serial.begin(9600);
  buttons[0]=2;
}
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);
  }
}






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


WEEK13 課堂作業


(CH05) 馬達轉轉

#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); myServo.write(angle); delay(15); }


(CH06) 用光發出聲音


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





(CH07) 按鈕聲音


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>=800 && keyVal<=1021){
    tone(8,notes[1]);
  }
  else if(keyVal>=400&& keyVal<=515){
    tone(8,notes[2]);
  }
  else if(keyVal==641){
    tone(8,notes[3]);
  }
  else {
    noTone(8);
  }
}



Week 13 課堂練習

提醒同學們,明天12/2(一) 是我們互動技術概論第13週的上課。
(1) 請不要忘了帶 Arduino Starter Kit 的實驗設備到學校哦!
(2) 明大要上課的內容是 Project 05 06 07 哦! 同學們今晚可以預習一下。
(3) 我們上課的目的,是為了讓同學們在期末完成自己構思的創意作品,同學們可以邊上課邊思考哦!
(4) 明天同學們記得帶 9V 的方塊電池(25元-60元一顆), 還有找找家裡有沒有一些要用電池的廉價的玩具, 我們可以在學校享受動手改裝的樂趣!


Project 06
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;
void setup() {
  // put your setup code here, to run once:
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() {
  // put your main code here, to run repeatedly: 
  sensorValue = analogRead(A0);
  int pitch = map(sensorValue,sensorLow,sensorHigh, 50,4000);
  tone(8,pitch,20);
  delay(10);

}



Project 07
int buttons[6];


int notes[] = {262,294,330,349};
void setup(){
  buttons[0] = 2;
  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);
  }
}



Project 05
#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);
}




Week 13

Lesson 5 Mode Cue
利用手去轉馬達,使得風扇轉動

#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);
  //這裡的 map function 可以把 0~1023 轉換到 0~179度
  //很方便的函示
  angle=map(potVal, 0, 1023, 0, 179);
  Serial.print(", angle: ");
  Serial.print(angle);
  Serial.print("\r\n");
  myServo.write(angle);
  delay(15);
}






Lesson 6 Light Theremin
利用光線的強弱來發出聲音

int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  //遮住/打開光敏電阻,讓程式修正最大和最小值
  while (millis() &lt; 5000) {
    sensorValue = analogRead(A0);
    if (sensorValue &gt; sensorHigh) {
      sensorHigh = sensorValue;
    }
    if (sensorValue &lt; sensorLow) {
      sensorLow = sensorValue;
    }
  }
  //開始進入
  digitalWrite(ledPin, LOW);
}

void loop() {
  sensorValue = analogRead(A0);
  //對應最高和最低的數值,對應為 50~4000 hz
  int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
  tone(8, pitch, 20);
  delay(10);
}





Lesson 7 Keyboard Instrument
按鍵發出樂器的聲音

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>=900 && keyVal<=1010) { tone(8,notes[1]); } else if(keyVal>=505 && keyVal<=511) { tone(8,notes[2]); } else if (keyVal>=512 && keyVal<=512) { tone(8,notes[3]); } else { noTone(8); } }