久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3068|回復: 0
打印 上一主題 下一主題
收起左側

關于自制的音樂播放器的一個小實驗

[復制鏈接]
跳轉到指定樓層
樓主
本實驗用到的是無源蜂鳴器傳感器模塊(Arduino拓展板盾板以及杜邦線每個實驗都要用,所以不再重復說明)。
如下圖所示,我們將蜂鳴器模塊的GND、VCC、以及IO口與Arduino拓展盾板的GND.+5V以及串口6相連接。

                              
然后接上USB連接線,導入程序。
  1. int speakerPin = 9;

  2. int length = 15; // the number of notes
  3. char notes[] = "ccggaagffeeddc "; // a space represents a rest
  4. int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
  5. int tempo = 300;

  6. void playTone(int tone, int duration) {
  7.   for (long i = 0; i < duration * 1000L; i += tone * 2) {
  8.     digitalWrite(speakerPin, HIGH);
  9.     delayMicroseconds(tone);
  10.     digitalWrite(speakerPin, LOW);
  11.     delayMicroseconds(tone);
  12.   }
  13. }

  14. void playNote(char note, int duration) {
  15.   char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  16.   int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  17.   // play the tone corresponding to the note name
  18.   for (int i = 0; i < 8; i++) {
  19.     if (names[i] == note) {
  20.       playTone(tones[i], duration);
  21.     }
  22.   }
  23. }

  24. void setup() {
  25.   pinMode(speakerPin, OUTPUT);
  26. }

  27. void loop() {
  28.   for (int i = 0; i < length; i++) {
  29.     if (notes[i] == ' ') {
  30.       delay(beats[i] * tempo); // rest
  31.     } else {
  32.       playNote(notes[i], beats[i] * tempo);
  33.     }

  34.     // pause between notes
  35.     delay(tempo / 2);
  36.   }
  37. }
復制代碼

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲一区网站 | 国产h在线| 国产精品免费一区二区 | 色婷婷国产 | 精品欧美一区二区精品久久 | 国产欧美日韩在线观看 | 中文字幕在线免费看 | 亚洲少妇一区 | 国产精品hd | 午夜在线 | 色综合五月天 | 久久久免费观看 | 欧美成人精品一区二区三区在线看 | 欧美乱强伦 | av每日更新 | 银杏av| 成人一级片| 99在线免费视频 | 四虎色| 色av网| 国产成人在线免费视频 | 日韩免费一区二区 | 久色精品| 精品日韩一区二区 | 精品1区2区3区 | 精品| 成人国产精品视频 | 免费特级毛片 | 日韩精品视频网站 | 久久久久久久久久国产 | 午夜色婷婷 | 国产精品不卡视频 | 国产午夜精品一区二区三区视频 | 天天草天天草 | 99免费视频 | 成人激情视频网 | 中文字幕av在线播放 | 天天干天天操天天 | 日韩免费看片 | 成人免费在线视频 | 欧美日韩一区二区三区四区 |