在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

用Lilypad制作音板的教程

李娜 ? 來源:Device Plus ? 作者:Device Plus ? 2023-02-08 13:43 ? 次閱讀

Arduino平臺的設(shè)計非常靈活,使用Uno等單個開發(fā)板就可以創(chuàng)建出無數(shù)項目。但是,專為執(zhí)行特定任務(wù)而設(shè)計的專用板對某些項目來說尤其有用。為了展示這一點,我們將用LilyPad MP3(一種變體Arduino開發(fā)板)來構(gòu)建一個音板。

變體開發(fā)板的工作原理

開源軟件平臺允許開發(fā)人員檢查和修改他們的代碼。同樣,像Arduino這樣的開源硬件平臺允許第三方構(gòu)建他們自己版本的兼容板。Arduino板的LilyPad系列就是這樣的一種變體。該板專為電子紡織品設(shè)計,可以縫制到織物項目中。這使其成為服裝和智能服裝的理想選擇。

poYBAGPbihCAScn7AAArFFOcbUw502.jpg

LilyPad MP3是LilyPad系列的另一個子變體,包括一個內(nèi)置SD卡讀卡器、一個立體聲音頻放大器和3.5毫米耳機插孔,以及五個預(yù)編程過的觸發(fā)器輸入。無需任何編碼設(shè)置,您最多可以連接五個觸發(fā)器來播放預(yù)先錄制的聲音文件。如果您曾在迪士尼見過可以播放一組預(yù)先編寫好的語句的星球大戰(zhàn)沖鋒隊 ,那么可以告訴您LilyPad MP3的功能與其非常相似。

雖然LilyPad MP3可以像任何Arduino板那樣編程,但是該項目的優(yōu)點是您可以在不修改任何現(xiàn)有代碼的情況下對音板進行設(shè)置。它可以向您證明為您的項目盡早選擇合適的開發(fā)板有多么值得。使用普通的Arduino Uno需要有一個外部擴展板才能具有與LilyPad MP3相同的功能,而且體積會更大。由于大多數(shù)Arduino板都可以與大部分草圖兼容,因此找到滿足您需求的外形尺寸可以為您省去大量的時間和麻煩。

所需組件

對于本項目,我們將演示LilyPad MP3如何在面包板上工作的,其實就是讓線路能夠正常工作。首先,您需要一個LilyPad MP3。

您還需要1-5個按鈕(只需要一個,但是LilyPad最多支持5個)、一個揚聲器(或耳機)和3.5毫米電纜。

由于LilyPad旨在用于服裝,您可以選擇使用一些線和針將設(shè)備縫制到外套、衣服或任何其他您想要裝上音板的地方。使用導(dǎo)電布線可以讓您將電線直接編織到衣服的面料中。

poYBAGPbihKALCLHAABcE2vMSpI330.jpg

代碼

如上所述,LilyPad MP3上默認觸發(fā)器草圖的代碼預(yù)裝在了每塊板上。您不需要上傳此文件,但查看這些代碼來了解工作原理會很有幫助。

// “Trigger” example sketch for Lilypad MP3 Player
// Mike Grusin, SparkFun Electronics
// http://www.sparkfun.com

// This sketch (which is preloaded onto the board by default),
// will play a specific audio file when one of the five trigger
// inputs (labeled T1 – T5) is momentarily grounded.

// You can place up to five audio files on the micro-SD card.
// These files should have the desired trigger number (1 to 5)
// as the first character in the filename. The rest of the
// filename can be anything you like. Long file names will work,
// but will be translated into short 8.3 names. We recommend using
// 8.3 format names without spaces, but the following characters
// are OK: .$%’-_@~`!(){}^#&. The VS1053 can play a variety of
// audio formats, see the datasheet for information.

// By default, a new trigger will interrupt a playing file, except
// itself. (In other words, a new trigger won’t restart an
// already-playing file). You can easily change this behavior by
// modifying the global variables “interrupt” and “interruptself”
// below.

// This sketch can output serial debugging information if desired
// by changing the global variable “debugging” to true. Note that
// this will take away trigger inputs 4 and 5, which are shared
// with the TX and RX lines. You can keep these lines connected to
// trigger switches and use the serial port as long as the triggers
// are normally open (not grounded) and remain ungrounded while the
// serial port is in use.

// Uses the SdFat library by William Greiman, which is supplied
// with this archive, or download from http://code.google.com/p/sdfatlib/

// Uses the SFEMP3Shield library by Bill Porter, which is supplied
// with this archive, or download from http://www.billporter.info/

// License:
// We use the “beerware” license for our firmware. You can do
// ANYTHING you want with this code. If you like it, and we meet
// someday, you can, but are under no obligation to, buy me a
// (root) beer in return.

// Have fun!
// -your friends at SparkFun

// Revision history:
// 1.0 initial release MDG 2012/11/01

// We’ll need a few libraries to access all this hardware!

#include // To talk to the SD card and MP3 chip
#include // SD card file system
#include // MP3 decoder chip

// Constants for the trigger input pins, which we’ll place
// in an array for convenience:

const int TRIG1 = A0;
const int TRIG2 = A4;
const int TRIG3 = A5;
const int TRIG4 = 1;
const int TRIG5 = 0;
int trigger[5] = {TRIG1, TRIG2, TRIG3, TRIG4, TRIG5};

// And a few outputs we’ll be using:

const int ROT_LEDR = 10; // Red LED in rotary encoder (optional)
const int EN_GPIO1 = A2; // Amp enable + MIDI/MP3 mode select
const int SD_CS = 9; // Chip Select for SD card

// Create library objects:

SFEMP3Shield MP3player;
SdFat sd;

// Set debugging = true if you’d like status messages sent
// to the serial port. Note that this will take over trigger
// inputs 4 and 5. (You can leave triggers connected to 4 and 5
// and still use the serial port, as long as you’re careful to
// NOT ground the triggers while you’re using the serial port).

boolean debugging = false;

// Set interrupt = false if you would like a triggered file to
// play all the way to the end. If this is set to true, new
// triggers will stop the playing file and start a new one.

boolean interrupt = true;

// Set interruptself = true if you want the above rule to also
// apply to the same trigger. In other words, if interrupt = true
// and interruptself = false, subsequent triggers on the same
// file will NOT start the file over. However, a different trigger
// WILL stop the original file and start a new one.

boolean interruptself = false;

// We’ll store the five filenames as arrays of characters.
// “Short” (8.3) filenames are used, followed by a null character.

char filename[5][13];

void setup()
{
int x, index;
SdFile file;
byte result;
char tempfilename[13];

// Set the five trigger pins as inputs, and turn on the
// internal pullup resistors:

for (x = 0; x <= 4; x++) { pinMode(trigger[x], INPUT); digitalWrite(trigger[x], HIGH); } // If serial port debugging is inconvenient, you can connect // a LED to the red channel of the rotary encoder to blink // startup error codes: pinMode(ROT_LEDR, OUTPUT); digitalWrite(ROT_LEDR, HIGH); // HIGH = off // The board uses a single I/O pin to select the // mode the MP3 chip will start up in (MP3 or MIDI), // and to enable/disable the amplifier chip: pinMode(EN_GPIO1, OUTPUT); digitalWrite(EN_GPIO1, LOW); // MP3 mode / amp off // If debugging is true, initialize the serial port: // (The ‘F’ stores constant strings in flash memory to save RAM) if (debugging) { Serial.begin(9600); Serial.println(F(“Lilypad MP3 Player trigger sketch”)); } // Initialize the SD card; SS = pin 9, half speed at first if (debugging) Serial.print(F(“initialize SD card… “)); result = sd.begin(SD_CS, SPI_HALF_SPEED); // 1 for success if (result != 1) // Problem initializing the SD card { if (debugging) Serial.print(F(“error, halting”)); errorBlink(1); // Halt forever, blink LED if present. } else if (debugging) Serial.println(F(“success!”)); // Start up the MP3 library if (debugging) Serial.print(F(“initialize MP3 chip… “)); result = MP3player.begin(); // 0 or 6 for success // Check the result, see the library readme for error codes. if ((result != 0) && (result != 6)) // Problem starting up { if (debugging) { Serial.print(F(“error code “)); Serial.print(result); Serial.print(F(“, halting.”)); } errorBlink(result); // Halt forever, blink red LED if present. } else if (debugging) Serial.println(F(“success!”)); // Now we’ll access the SD card to look for any (audio) files // starting with the characters ‘1’ to ‘5’: if (debugging) Serial.println(F(“reading root directory”)); // Start at the first file in root and step through all of them: sd.chdir(“/”, true); while (file.openNext(sd.vwd(), O_READ)) { // get filename file.getFilename(tempfilename); // Does the filename start with char ‘1’ through ‘5’? if (tempfilename[0] >= ‘1’ && tempfilename[0] <= ‘5’)
{
// Yes! subtract char ‘1’ to get an index of 0 through 4.

index = tempfilename[0] – ‘1’;

// Copy the data to our filename array.

strcpy(filename[index], tempfilename);

if (debugging) // Print out file number and name
{
Serial.print(F(“found a file with a leading “));
Serial.print(index + 1);
Serial.print(F(“: “));
Serial.println(filename[index]);
}
}
else if (debugging)
{
Serial.print(F(“found a file w/o a leading number: “));
Serial.println(tempfilename);
}

file.close();
}

if (debugging)
Serial.println(F(“done reading root directory”));

if (debugging) // List all the files we saved:
{
for(x = 0; x <= 4; x++)
{
Serial.print(F(“trigger “));
Serial.print(x + 1);
Serial.print(F(“: “));
Serial.println(filename[x]);
}
}

// Set the VS1053 volume. 0 is loudest, 255 is lowest (off):

MP3player.setVolume(10, 10);

// Turn on the amplifier chip:

digitalWrite(EN_GPIO1, HIGH);
delay(2);
}

void loop()
{
int t; // current trigger
static int last_t; // previous (playing) trigger
int x;
byte result;

// Step through the trigger inputs, looking for LOW signals.
// The internal pullup resistors will keep them HIGH when
// there is no connection to the input.

// If serial debugging is on, only check triggers 1-3,
// otherwise check triggers 1-5.

for(t = 1; t <= (debugging ? 3 : 5); t++)
{
// The trigger pins are stored in the inputs[] array.
// Read the pin and check if it is LOW (triggered).

if (digitalRead(trigger[t – 1]) == LOW)
{
// Wait for trigger to return high for a solid 50ms
// (necessary to avoid switch bounce on T2 and T3
// since we need those free for I2C control of the
// amplifier)

x = 0;
while(x < 50)
{
if (digitalRead(trigger[t – 1]) == HIGH)
x++;
else
x = 0;
delay(1);
}

if (debugging)
{
Serial.print(F(“got trigger “));
Serial.println(t);
}

// Do we have a valid filename for this trigger?
// (Invalid filenames will have 0 as the first character)

if (filename[t – 1][0] == 0)
{
if (debugging)
Serial.println(F(“no file with that number”));
}
else // We do have a filename for this trigger!
{
// If a file is already playing, and we’ve chosen to
// allow playback to be interrupted by a new trigger,
// stop the playback before playing the new file.

if (interrupt && MP3player.isPlaying() && ((t != last_t) || interruptself))
{
if (debugging)
Serial.println(F(“stopping playback”));

MP3player.stopTrack();
}

// Play the filename associated with the trigger number.
// (If a file is already playing, this command will fail
// with error #2).

result = MP3player.playMP3(filename[t – 1]);

if (result == 0) last_t = t; // Save playing trigger

if(debugging)
{
if(result != 0)
{
Serial.print(F(“error “));
Serial.print(result);
Serial.print(F(” when trying to play track “));
}
else
{
Serial.print(F(“playing “));
}
Serial.println(filename[t – 1]);
}
}
}
}
}

void errorBlink(int blinks)
{
// The following function will blink the red LED in the rotary
// encoder (optional) a given number of times and repeat forever.
// This is so you can see any startup error codes without having
// to use the serial monitor window.

int x;

while(true) // Loop forever
{
for (x = 0; x < blinks; x++) // Blink the given number of times
{
digitalWrite(ROT_LEDR, LOW); // Turn LED ON
delay(250);
digitalWrite(ROT_LEDR, HIGH); // Turn LED OFF
delay(250);
}
delay(1500); // Longer pause between blink-groups
}
}

雖然逐行看下來代碼實在太多了(而且很多都在本項目中用不到),但是有幾個關(guān)鍵點值得強調(diào)。首先,有一些函數(shù)是Bill Porter的MP3播放器庫的一部分。這些函數(shù)通過VS1053B解碼芯片控制音頻文件。這些獨特的函數(shù)包括:

● setVolume(): 該函數(shù)可以調(diào)節(jié)輸出音量的級別。
● isPlaying(): 該函數(shù)可用于確定當前是否正在播放MP3(可用于中斷或停止播放)。
● stopTrack(): 可以停止當前正在播放的曲目。
● playMP3(): 該函數(shù)用于播放SD卡中的文件。默認草圖設(shè)置為播放與輸入所連接觸發(fā)器匹配的文件。

要在LilyPad上設(shè)置音軌,您最多可以將五個音頻文件添加到微SD卡中。盡管LilyPad的名稱是MP3,但是它支持多種音頻文件格式。您可以在此處找到所支持的格式列表。您可以隨意命名文件,只要文件名以1到5之間的數(shù)字開頭即可。

默認草圖將播放與激活的觸發(fā)器對應(yīng)的音頻文件。觸發(fā)器1(在LilyPad上標記為T1)將激活以1開頭的音頻文件。觸發(fā)器2將播放以2開頭的文件,以此類推。只要您正確命名音頻文件,就不必對代碼進行任何處理。

接線

將所有組件連接到LilyPad很簡單。將微SD卡插入微SD卡槽,然后將揚聲器或一副耳機插入耳機插孔。如果您想將揚聲器直接連接到開發(fā)板,LilyPad還具有用于左右揚聲器的正負極觸點。

接下來,將按鈕連接到您要使用的每個觸發(fā)器。按鈕的一側(cè)連接到GND,而另一側(cè)連接到您要激活的觸發(fā)器觸點。LilyPad上的觸發(fā)器觸點中有一個大圓形觸點和一個緊鄰大觸點的較小觸點。您可以將電線焊接到較小的觸點,或?qū)㈦娋€纏繞在較大的觸點上。

按下按鈕,此時應(yīng)該會觸發(fā)音頻文件的播放。確認接線正常后,您就可以嘗試使用導(dǎo)電布線將接線縫入織物中了。

這篇文章來源于DevicePlus.com英語網(wǎng)站的翻譯稿。

DevicePlus 編輯團隊

設(shè)備升級版適用于所有熱愛電子和機電一體化的人。

審核編輯黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 觸發(fā)器
    +關(guān)注

    關(guān)注

    14

    文章

    2033

    瀏覽量

    61956
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4891

    瀏覽量

    70352
  • Arduino
    +關(guān)注

    關(guān)注

    189

    文章

    6494

    瀏覽量

    190300
收藏 人收藏

    評論

    相關(guān)推薦
    熱點推薦

    怎樣制作一個錄音板

    畢業(yè)設(shè)計題目是錄音板,對此毫無頭緒,資料也寥寥無幾。有沒有了解錄音板相關(guān)知識和制作方法的人啊~~~
    發(fā)表于 02-17 15:07

    誰會制作音板啊?!

    誰有錄音板制作的相關(guān)資料,論文啊~~~~急~~~~~~~~~~~~~~~
    發(fā)表于 03-02 13:27

    求錄音板制作的相關(guān)論文資料

    誰有錄音板制作的資料和論文啊?一直找不到相關(guān)資料,急~~~~
    發(fā)表于 03-02 13:30

    關(guān)于isd1700錄音板

    請問isd1700配套的那個錄音板可以普通的51單片機開發(fā)板代替來錄音嗎?
    發(fā)表于 01-25 16:46

    EasyEDA開源硬件——Arduino LilyPad 帶USB 的Atmega32U4板

    很簡單,僅僅更加簡單。我們已經(jīng)升級了簡單板子從而創(chuàng)建LilyPad USB 通過新的ATMega32U4.替換 經(jīng)典的ATMega328。 這不僅僅意味著它正在多種多樣的最新和最偉大的啟動加載器中
    發(fā)表于 01-20 18:37

    EasyEDA開源硬件——LilyPad MP3

    LilyPad 紡織先得一部分,這塊板可以用來給你的織物創(chuàng)作以音樂,以及其他能夠放在微SD卡內(nèi)的聲音。它可以3.7V鋰電池充電,或者一個外部的3.5V-6V 的電源。當五個觸發(fā)輸入接地的時候可以播放
    發(fā)表于 01-21 15:42

    EasyEDA開源硬件——LilyPad Arduino SimpleSnap (Open hardware)

    本帖最后由 GerryChen 于 2016-1-28 18:31 編輯 LilyPad Arduino SimpleSnap (Open hardware)LilyPad Arduino
    發(fā)表于 01-25 18:49

    EasyEDA開源硬件項目——LilyPad 簡單電源

    Description: The LilyPad Simple Power is a simple e-textile board that lets you connect and charge
    發(fā)表于 02-02 10:20

    EasyEDA開源硬件——LilyPad 供應(yīng)電源

    to power your LilyPad circuit. Good up to 200mA. Short circuit protected.This board has AAA battery clips
    發(fā)表于 02-02 10:24

    EasyEDA開源硬件——LilyPad像素板

    Description: We know you love adding color to your e-textiles, adding the LilyPad Pixel Board
    發(fā)表于 02-02 10:29

    EasyEDA開源硬件電路——LilyPad Xbee 模塊

    Description: The LilyPad XBee is a breakout board for the popular XBee modules that can be sewn
    發(fā)表于 02-02 10:37

    調(diào)音板--protel源文件

    調(diào)音板--protel源文件 原理圖 PCB圖 都是源文件
    發(fā)表于 03-10 17:06 ?0次下載

    Arduino Lilypad可控NeoPixel耳環(huán)的制作

    3個不同的地方針和繩子縫合NeoPixel和Lilypad。兩者都有足夠的洞。你可以從任何地方離開。
    的頭像 發(fā)表于 11-07 10:47 ?2752次閱讀

    Arduino LilyPad控制的NeoPixel耳環(huán)

    電子發(fā)燒友網(wǎng)站提供《Arduino LilyPad控制的NeoPixel耳環(huán).zip》資料免費下載
    發(fā)表于 12-12 09:29 ?0次下載
    Arduino <b class='flag-5'>LilyPad</b>控制的NeoPixel耳環(huán)

    無源調(diào)音板好還是有源調(diào)音板

    無源調(diào)音板和有源調(diào)音板是音頻處理中常用的兩種設(shè)備。它們在音頻信號處理和聲音調(diào)節(jié)方面有著不同的特點和功能。無源調(diào)音板是一種簡單的信號控制設(shè)備,主要用于音頻信號的調(diào)節(jié)和控制,而有源調(diào)音板
    的頭像 發(fā)表于 12-22 15:57 ?3720次閱讀
    主站蜘蛛池模板: 久久综合成人网 | 另类free性欧美护士 | 天堂网 | 亚洲mm8成为人影院 亚洲qingse中文在线 | 欧美色操| 牛仔裤美女国产精品毛片 | 美女扒开腿让男生桶爽网站 | 夜夜夜夜曰天天天天拍国产 | 日本人69xxxxx | 免费a级毛片出奶水 | 午夜毛片免费观看视频 | 亚洲国产精品久久久久婷婷软件 | 欧美一级黄色片视频 | 日本不卡一区二区三区在线观看 | 手机看片自拍自自拍日韩免费 | 色综合久久久久久久久久久 | 欧美人与动性xxxxbbbb | 国产女乱淫真高清免费视频 | 免费h视频在线观看 | 又粗又爽又色男女乱淫播放男女 | 国产精品视频久久久久久 | 欧美色图狠狠干 | 亚洲一区二区电影 | 手机在线看片你懂得 | 欧美成人xxxx | 亚洲精品91香蕉综合区 | www.五月婷婷 | 国产毛片一区二区三区精品 | 色综合久久综合欧美综合图片 | 婷婷综合在线观看丁香 | 久久久久久88色偷偷 | 乱说欲小说又粗又长 | 婷婷六月丁香色婷婷网 | 四虎永久精品免费网址大全 | 久久国产精品免费网站 | 黄色一级视频欧美 | 韩国美女丝袜一区二区 | 黄网站观看 | 精品久久天干天天天按摩 | 中文字幕1区 | 牛仔裤美女国产精品毛片 |