SlideShare a Scribd company logo
1 of 39
Download to read offline
Arduino Plus
MakerBar Taipei Workshop
•
•
聲音波形
模擬波形
聲音頻率
頻率,單位為赫茲 (括號內為半⾳音距離,"(0)"為中央C)
⼋八度 0 1 2 3 4 5 6 7 8 9
C 16.352	
  
(−48)
32.703	
  
(−36)
65.406	
  
(−24)
130.81	
  
(−12)
261.63	
  
(0)
523.25	
  
(+12)
1046.5	
  
(+24)
2093.0	
  
(+36)
4186.0	
  
(+48)
8372.0	
  
(+60)
D 18.354	
  
(−46)
36.708	
  
(−34)
73.416	
  
(−22)
146.83	
  
(−10)
293.66	
  
(+2)
587.33	
  
(+14)
1174.7	
  
(+26)
2349.3	
  
(+38)
4698.6	
  
(+50)
9397.3	
  
(+62)
E 20.602	
  
(−44)
41.203	
  
(−32)
82.407	
  
(−20)
164.81	
  
(−8)
329.63	
  
(+4)
659.26	
  
(+16)
1318.5	
  
(+28)
2637.0	
  
(+40)
5274.0	
  
(+52)
10548	
  
(+64)
F 21.827	
  
(−43)
43.654	
  
(−31)
87.307	
  
(−19)
174.61	
  
(−7)
349.23	
  
(+5)
698.46	
  
(+17)
1396.9	
  
(+29)
2793.8	
  
(+41)
5587.7	
  
(+53)
11175	
  
(+65)
G 24.500	
  
(−41)
48.999	
  
(−29)
97.999	
  
(−17)
196.00	
  
(−5)
392.00	
  
(+7)
783.99	
  
(+19)
1568.0	
  
(+31)
3136.0	
  
(+43)
6271.9	
  
(+55)
12544	
  
(+67)
A 27.500	
  
(−39)
55.000	
  
(−27)
110.00	
  
(−15)
220.00	
  
(−3)
440.00	
  
(+9)
880.00	
  
(+21)
1760.0	
  
(+33)
3520.0	
  
(+45)
7040.0	
  
(+57)
14080	
  
(+69)
B 30.868	
  
(−37)
61.735	
  
(−25)
123.47	
  
(−13)
246.94	
  
(−1)
493.88	
  
(+11)
987.77	
  
(+23)
1975.5	
  
(+35)
3951.1	
  
(+47)
7902.1	
  
(+59)
15804	
  
(+71)
MIDI
樂器數位介面
音樂
Music
MIDI
• 樂器數位介面(Musical Instrument Digital
Interface,簡稱MIDI)是一個工業標準的電子通訊協
定,為電子樂器等演奏裝置(如合成器)定義各種音符
或彈奏碼,容許電子樂器、電腦、手機或其它的舞台演
出配備彼此連接,調整和同步,得以即時交換演奏資
料。
• MIDI不傳送聲音,只傳送像是音調和音樂強度的資
料,音量,顫音和相位等參數的控制訊號,還有設定節
奏的時鐘信號。在不同的電腦上,輸出的聲音也因音源
器不同而有差異。
揚聲器
揚聲器播放A調,其頻率為440Hz,即每秒振動440次,揚聲器輸出440Hz
的交流電,每秒440次電流改變。當電線圈與揚聲器薄膜⼀一起振動,推
動周圍的空氣振動,揚聲器由此產⽣生聲⾳音。
揚聲器把電流頻率轉換成聲⾳音。
MIDI範例

EX1
電路圖
程式EX1
void setup() {
}
void loop() {
tone(6, 440, 200);
delay(200);
noTone(6);
}
Pin6播放「A」midi音,
持續0.2秒
tone(pin,	
  frequency,	
  duration)
#include ”pitches.h”
void setup() {
}
新增
tone(6, NOTE_A4, 200);
delay(200);
更改
14
• Input A0電位器:0 ~ 1023
• Output 頻率:100 ~ 2000
• int x = map(analogRead(A0), 0, 1023, 100,
2000);
• tone(6, x , 200);
EX2_1
EX2_1
15
void	
  setup(){	
  
	
  Serial.begin(9600);	
  
	
  }	
  
void	
  loop()	
  {	
  
	
  	
  int	
  sensor	
  =	
  analogRead(A0);	
  
	
  	
  int	
  x	
  =	
  map(analogRead(A0),	
  0,	
  1023,	
  100,	
  2000);	
  
	
  	
  tone(6,	
  x	
  ,	
  200);	
  	
  
	
  	
  Serial.println(x);	
  
}//end	
  loop	
  
MIDI範例

EX2_2
17
程式EX2_2
void	
  setup(){	
  
	
  Serial.begin(9600);	
  
	
  }	
  
void	
  loop()	
  {	
  
	
  	
  int	
  sensor	
  =	
  analogRead(A0);	
  
	
  	
  if(sensor	
  >	
  500	
  &&	
  sensor	
  <	
  800)	
  	
  
	
  	
  {	
  	
  	
  
	
  	
  	
  	
  tone(6,	
  440,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  	
  
else	
  if	
  (sensor	
  >	
  0	
  &&	
  sensor	
  <	
  500){	
  
	
  	
  	
  	
  tone(6,	
  220,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  else{	
  
	
  	
  	
  	
  	
  tone(6,	
  880,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
	
  	
  	
  Serial.println(sensor);	
  	
  
	
  	
  }	
  
}//end	
  loop
practice time-副程式
void	
  setup(){	
  
	
  Serial.begin(9600);	
  
	
  }	
  
void	
  loop()	
  {	
  
	
  	
  int	
  sensor	
  =	
  analogRead(A0);	
  
	
  	
  if(sensor	
  >	
  500	
  &&	
  sensor	
  <	
  800)	
  	
  
	
  	
  {	
  	
  	
  
	
  	
  	
  	
  tone(6,	
  440,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  	
  
	
  	
  	
  	
  else	
  if	
  (sensor	
  >	
  0	
  &&	
  sensor	
  <	
  500){	
  
	
  	
  	
  	
  tone(6,	
  220,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  else{	
  
	
  	
  	
  	
  	
  play();	
  
	
  	
  	
  	
  	
  Serial.println(	
  sensor);	
  	
  
	
  	
  }	
  
}//end	
  loop	
  
void	
  play()	
  {	
  
	
  	
  	
  	
  tone(6,	
  880,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
}
19
程式EX2_3 : 加入play(int freq)void	
  setup(){	
  
	
  Serial.begin(9600);	
  
	
  }	
  
void	
  loop()	
  {	
  
	
  	
  int	
  sensor	
  =	
  analogRead(A0);	
  
	
  	
  if(sensor	
  >	
  500	
  &&	
  sensor	
  <	
  800)	
  	
  
	
  	
  {	
  	
  	
  
	
  	
  	
  	
  play(440);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  	
  	
  else	
  if	
  (sensor	
  >	
  0	
  &&	
  sensor	
  <	
  500){	
  
	
  	
  	
  	
  play(220);	
  
	
  	
  	
  	
  Serial.println(sensor);	
  
	
  	
  }	
  
	
  	
  else{	
  
	
  	
  	
  play(880);	
  
	
  	
  	
  Serial.println(sensor);	
  	
  
	
  	
  }	
  
}
void	
  play(int	
  freq)	
  {	
  
	
  	
  	
  	
  tone(6,	
  freq,	
  200);	
  
	
  	
  	
  	
  delay(200);	
  
	
  	
  	
  	
  noTone(6);	
  
}
MIDI
樂器數位介面
音樂
Music
SD Shield
SPI?
串列外設介面(Serial Peripheral Interface Bus,
SPI),類似I²C,是一種4線同步序列資料協定,適
用於可攜式裝置平台系統,但使用率較I²C少。串列
外設介面一般是4線,有時亦可為3線,有別於I²C的
2線,以及1-Wire。
新增函式庫
• 將「SimpleSDAudio」移至arduinolibraries裡
音樂轉檔(WAV→AFM)
27
SimpleSDAudiotoolsArduino with 16
MHzconverted
放⼊入SD卡的最外層
撥放音樂

EX3
電路圖
注意順序!!!!
#include <SimpleSDAudio.h>
void setup()
{
SdPlay.setSDCSPin(10);
SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_STEREO |SSDA_MODE_AUTOWORKER);
if(!SdPlay.setFile(“A16.AFM”))
{
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
}
else
{
Serial.println(F("found."));
SdPlay.play();
}
}
音樂撥放器

EX4
電路圖
確認SD卡
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO |
SSDA_MODE_AUTOWORKER)) {
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card is inserted?"));
Serial.println(F("* Is your wiring correct?"));
Serial.println(F("* maybe you need to change the chipSelect
pin to match your shield or module?"));
Serial.print(F("Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
}
讀取SD卡內部資料
Serial.println(F("Files on card:"));
SdPlay.dir(&DirCallback);
選擇檔案
ReEnter:
count = 0;
Serial.println(F("rnEnter filename (send newline after input):"));
do {
while(!Serial.available()) ;
c = Serial.read();

…….



if(!SdPlay.setFile(AudioFileName)) {
Serial.println(F(" not found on card! Error code: "));
……
選擇狀態
Serial.println(F("Press s for stop, p for play, h for pause, f to
select new file, d for deinit, v to view status."));
flag = 1;
while(flag) {
SdPlay.worker(); // You can remove this line if you like -
worker is not necessary
if(Serial.available()) {
c = Serial.read();
……
接下來可以做什麼?
• 音頻放大器
• 逛逛電子商場
• 找尋尋有趣的專題
http://www.goodliffe.org.uk/arduino/mp3player.php
Facebook → CAVEDU教育團隊

More Related Content

What's hot

What's hot (20)

Chapter 1 what is arduino
Chapter 1 what is arduinoChapter 1 what is arduino
Chapter 1 what is arduino
 
Arduino導論
Arduino導論Arduino導論
Arduino導論
 
Arduino基礎IO控制
Arduino基礎IO控制Arduino基礎IO控制
Arduino基礎IO控制
 
Arduino感測應用
Arduino感測應用Arduino感測應用
Arduino感測應用
 
Arduino序列通訊應用
Arduino序列通訊應用Arduino序列通訊應用
Arduino序列通訊應用
 
HC 05藍芽模組連線
HC 05藍芽模組連線HC 05藍芽模組連線
HC 05藍芽模組連線
 
認識 RoBoard 硬體
認識 RoBoard 硬體認識 RoBoard 硬體
認識 RoBoard 硬體
 
Arduino簡介
Arduino簡介Arduino簡介
Arduino簡介
 
使用 Arduino 控制 ESP8266 的各種方式
使用 Arduino 控制 ESP8266 的各種方式使用 Arduino 控制 ESP8266 的各種方式
使用 Arduino 控制 ESP8266 的各種方式
 
Arduino AMA中級認證術科實作 all
Arduino AMA中級認證術科實作 allArduino AMA中級認證術科實作 all
Arduino AMA中級認證術科實作 all
 
nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論nodeMCU IOT教學03 - NodeMCU導論
nodeMCU IOT教學03 - NodeMCU導論
 
Arduino程式快速入門
Arduino程式快速入門Arduino程式快速入門
Arduino程式快速入門
 
Arduino程式快速入門
Arduino程式快速入門Arduino程式快速入門
Arduino程式快速入門
 
Arduino Basic
Arduino BasicArduino Basic
Arduino Basic
 
Chapter 2 XBee無線傳輸
Chapter 2 XBee無線傳輸Chapter 2 XBee無線傳輸
Chapter 2 XBee無線傳輸
 
RoBoard 與 Lego NXT Sensors 之連接
RoBoard 與 Lego NXT Sensors 之連接RoBoard 與 Lego NXT Sensors 之連接
RoBoard 與 Lego NXT Sensors 之連接
 
瞻營全電子_六足機器人(二)
瞻營全電子_六足機器人(二)瞻營全電子_六足機器人(二)
瞻營全電子_六足機器人(二)
 
Microbit 1 introduction
Microbit 1 introductionMicrobit 1 introduction
Microbit 1 introduction
 
第6章 输入输出技术
第6章 输入输出技术第6章 输入输出技术
第6章 输入输出技术
 
3D Printer 韌體原始碼解析心得 (以 Marlin 為對象)
3D Printer 韌體原始碼解析心得 (以 Marlin 為對象)3D Printer 韌體原始碼解析心得 (以 Marlin 為對象)
3D Printer 韌體原始碼解析心得 (以 Marlin 為對象)
 

More from CAVEDU Education

Google TPU Edge SBC_190424
Google TPU Edge SBC_190424Google TPU Edge SBC_190424
Google TPU Edge SBC_190424CAVEDU Education
 
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...CAVEDU Education
 
BBC Micro:bit beginner project
BBC Micro:bit beginner projectBBC Micro:bit beginner project
BBC Micro:bit beginner projectCAVEDU Education
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 CAVEDU Education
 
Latte panda workshop_japan
Latte panda workshop_japanLatte panda workshop_japan
Latte panda workshop_japanCAVEDU Education
 
拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707CAVEDU Education
 
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeLinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeCAVEDU Education
 
170615 國中小自造者教育師資培訓營
170615  國中小自造者教育師資培訓營170615  國中小自造者教育師資培訓營
170615 國中小自造者教育師資培訓營CAVEDU Education
 
170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板CAVEDU Education
 
Maker Movement and Education in Taiwan
Maker Movement and Education in TaiwanMaker Movement and Education in Taiwan
Maker Movement and Education in TaiwanCAVEDU Education
 
物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行CAVEDU Education
 
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireIBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireCAVEDU Education
 
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireAAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireCAVEDU Education
 
物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台CAVEDU Education
 
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座FinalCAVEDU Education
 
LinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsLinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsCAVEDU Education
 
LinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceLinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceCAVEDU Education
 

More from CAVEDU Education (20)

Google TPU Edge SBC_190424
Google TPU Edge SBC_190424Google TPU Edge SBC_190424
Google TPU Edge SBC_190424
 
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
 
180321 MIT見聞分享
180321   MIT見聞分享180321   MIT見聞分享
180321 MIT見聞分享
 
BBC Micro:bit beginner project
BBC Micro:bit beginner projectBBC Micro:bit beginner project
BBC Micro:bit beginner project
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697
 
Latte panda workshop_japan
Latte panda workshop_japanLatte panda workshop_japan
Latte panda workshop_japan
 
拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707
 
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeLinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
 
170615 國中小自造者教育師資培訓營
170615  國中小自造者教育師資培訓營170615  國中小自造者教育師資培訓營
170615 國中小自造者教育師資培訓營
 
170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板
 
LinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorialLinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorial
 
Maker Movement and Education in Taiwan
Maker Movement and Education in TaiwanMaker Movement and Education in Taiwan
Maker Movement and Education in Taiwan
 
物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行
 
161123
161123161123
161123
 
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireIBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
 
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireAAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
 
物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台
 
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
 
LinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsLinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- Basics
 
LinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceLinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud service
 

Arduino 習作工坊 - Lesson 3 電音之夜