SlideShare a Scribd company logo
Arduino Plus
MakerBar Taipei Workshop
Arduino 習作工坊 -  Lesson 3 電音之夜
•
•
聲音波形
模擬波形
聲音頻率
頻率,單位為赫茲 (括號內為半⾳音距離,"(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。
Arduino 習作工坊 -  Lesson 3 電音之夜
新增函式庫
• 將「SimpleSDAudio」移至arduinolibraries裡
音樂轉檔(WAV→AFM)
Arduino 習作工坊 -  Lesson 3 電音之夜
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

PDF
Arduino 習作工坊 - Lesson 4 通訊之夜
PPTX
Arduino 習作工坊#2 - 動力之夜150114
PDF
Chapter 3 XBee無線遙控車
PPTX
Arduino 習作工坊 - Lesson 2 動力之夜
PDF
Arduino藍牙傳輸應用
PDF
Arduino序列通訊
PDF
Arduino overview
PDF
Arduino相關型錄
Arduino 習作工坊 - Lesson 4 通訊之夜
Arduino 習作工坊#2 - 動力之夜150114
Chapter 3 XBee無線遙控車
Arduino 習作工坊 - Lesson 2 動力之夜
Arduino藍牙傳輸應用
Arduino序列通訊
Arduino overview
Arduino相關型錄

What's hot (20)

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

More from CAVEDU Education (20)

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

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