欧美午夜欧美,台湾成人av,久久av一区,最近看过的日韩成人

電子開(kāi)發(fā)網(wǎng)

電子開(kāi)發(fā)網(wǎng)電子設(shè)計(jì) | 電子開(kāi)發(fā)網(wǎng)Rss 2.0 會(huì)員中心 會(huì)員注冊(cè)
搜索: 您現(xiàn)在的位置: 電子開(kāi)發(fā)網(wǎng) >> 基礎(chǔ)入門(mén) >> Arduino開(kāi)發(fā)學(xué)習(xí) >> 正文

使用Arduino播放《星球大戰(zhàn)》音樂(lè) Arduino播放音樂(lè)

作者:佚名    文章來(lái)源:本站原創(chuàng)    點(diǎn)擊數(shù):    更新時(shí)間:2019-05-31

本篇文章,我們將使用Arduino制作一個(gè)播放 《星球大戰(zhàn)》音樂(lè)的裝置。

原件清單

  1. Arduino UNO
  2. 蜂鳴器
  3. 連接線

電路圖

Arduino音樂(lè)播放器 

Arduino音樂(lè)播放器

電路很簡(jiǎn)單,只需要把蜂鳴器的正極連接到Arduino UNO的數(shù)字針5,負(fù)極連接到GND即可完成。

代碼

這是一個(gè)非常簡(jiǎn)單的項(xiàng)目,項(xiàng)目的硬件部分對(duì)每一個(gè)人來(lái)說(shuō)均不存在困難,稍微困難一點(diǎn)的應(yīng)該是代碼部分,下面提供本項(xiàng)目完整的代碼,供大家參考。重點(diǎn)是各種聲音的數(shù)值,完整代碼如下:

**/
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
const int buzzerPin = 5;
const int ledPin1 = 12;
const int ledPin2 = 13;
int counter = 0;
void setup()
{
//Setup pin modes
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
//Play first section
firstSection();
//Play second section
secondSection();
//Variant 1
beep(f, 250); 
beep(gS, 500); 
beep(f, 350); 
beep(a, 125);
beep(cH, 500);
beep(a, 375); 
beep(cH, 125);
beep(eH, 650);
delay(500);
//Repeat second section
secondSection();
//Variant 2
beep(f, 250); 
beep(gS, 500); 
beep(f, 375); 
beep(cH, 125);
beep(a, 500); 
beep(f, 375); 
beep(cH, 125);
beep(a, 650); 
delay(650);
}
void beep(int note, int duration)
{
//Play tone on buzzerPin
tone(buzzerPin, note, duration);
//Play different LED depending on value of 'counter'
if(counter % 2 == 0)
{
digitalWrite(ledPin1, HIGH);
delay(duration);
digitalWrite(ledPin1, LOW);
}else
{
digitalWrite(ledPin2, HIGH);
delay(duration);
digitalWrite(ledPin2, LOW);
}
//Stop tone on buzzerPin
noTone(buzzerPin);
delay(50);
//Increment counter
counter++;
}
void firstSection()
{
beep(a, 500);
beep(a, 500); 
beep(a, 500);
beep(f, 350);
beep(cH, 150); 
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
delay(500);
beep(eH, 500);
beep(eH, 500);
beep(eH, 500); 
beep(fH, 350);
beep(cH, 150);
beep(gS, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
delay(500);
}
void secondSection()
{
beep(aH, 500);
beep(a, 300);
beep(a, 150);
beep(aH, 500);
beep(gSH, 325);
beep(gH, 175);
beep(fSH, 125);
beep(fH, 125); 
beep(fSH, 250);
delay(325);
beep(aS, 250);
beep(dSH, 500);
beep(dH, 325); 
beep(cSH, 175); 
beep(cH, 125); 
beep(b, 125); 
beep(cH, 250); 
delay(350);
}
Tags:Arduino,播放音樂(lè)  
責(zé)任編輯:admin
  • 上一個(gè)文章:
  • 下一個(gè)文章:
  • 請(qǐng)文明參與討論,禁止漫罵攻擊,不要惡意評(píng)論、違禁詞語(yǔ)。 昵稱:
    1分 2分 3分 4分 5分

    還可以輸入 200 個(gè)字
    [ 查看全部 ] 網(wǎng)友評(píng)論
    關(guān)于我們 - 聯(lián)系我們 - 廣告服務(wù) - 友情鏈接 - 網(wǎng)站地圖 - 版權(quán)聲明 - 在線幫助 - 文章列表
    返回頂部
    刷新頁(yè)面
    下到頁(yè)底
    晶體管查詢
    主站蜘蛛池模板: 阜康市| 清远市| 门头沟区| 上栗县| 浦北县| 壤塘县| 南阳市| 深圳市| 丹阳市| 平潭县| 嘉峪关市| 宣恩县| 濮阳市| 阿拉尔市| 雅安市| 夏邑县| 阳新县| 光泽县| 定陶县| 定州市| 松江区| 金塔县| 茶陵县| 临夏市| 扎兰屯市| 堆龙德庆县| 丰顺县| 美姑县| 营口市| 禹州市| 大冶市| 巴林右旗| 若羌县| 岳池县| 海丰县| 左云县| 林州市| 平武县| 微山县| 涟水县| 静海县|