×

Arduino UNO婴儿高脚椅音乐剧

消耗积分:0 | 格式:zip | 大小:0.26 MB | 2022-12-02

张丽

分享资料个

描述

如果没有您一直在看,要让婴儿保持忙碌和安全绝非易事。

这个项目的目的是为所有年龄段的孩子创造一个有趣的高脚椅!

本教程的主要项目是设置一个游戏,当宝宝按下按钮时,同色灯亮并播放声音

游戏可以很容易地变成更复杂的游戏,当你的宝宝长大后,他们仍然会玩得开心

和工作他们的记忆!

第 1 步:收集您的零件和工具

这个项目我们不需要太多东西,最昂贵的部分将是高脚椅。

我们会需要:

第 2 步:连接

在这一部分中,我们将看到将所有东西放在高脚椅上之前的项目模拟。

对于LED,负极连接到电阻器,正极连接到引脚。

一旦它工作,只需要用真正的按钮和灯焊接所有东西

第 3 步:代码

我修改了该站点的代码,以便在按下按钮时两个仅播放 2 个音符并打开灯。

将代码加载到arduino

#define NOTE_C3 131
#define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494

// notes in the melody: from guitar study by Sor int melody[] = { NOTE_G3, NOTE_G3, };

int melody2[] = { NOTE_E3, NOTE_C4,};

int melody3[] = { NOTE_B3, NOTE_B3, };

int melody4[] = { NOTE_A3, NOTE_D4, };

//Les PIN arduino n*13,12,11,10 sont pour les leds

int ledPin = 13; int ledPin2 = 12; int ledPin3 = 11; int ledPin4 = 10; int inPin = 2; int inPin2 = 3; int inPin3 = 4; int inPin4 = 5; int val = 0; int vall = 0;

int valll = 0; int vallll = 0;

// note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2 };

void setup() { pinMode(2, INPUT_PULLUP); // push-button switch on pin 2, use internal pull-up resistor pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP);

pinMode(ledPin, OUTPUT); // declare LED as output

PlayTune(); // play tune at start-up }

void loop() {

// play tune again if button on digital pin 2 is pressed //pinMode(ledPin, OUTPUT); if (!digitalRead(5)) { vallll = digitalRead(inPin4); // read input value if (val == HIGH) { // check if the input is HIGH (button released) digitalWrite(ledPin4, LOW); // turn LED OFF } else { digitalWrite(ledPin4, HIGH); // turn LED ON delay(200); digitalWrite(ledPin4, LOW); } void PlayTune();

{ // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 2; thisNote++) { //le chffre 2 réprésente le temps que dure la //mélodie

// to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1500 / noteDurations[thisNote]; tone(8, melody4[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8);

} } }

if (!digitalRead(4)) {

val = digitalRead(inPin3); // read input value if (valll == HIGH) { // check if the input is HIGH (button released) digitalWrite(ledPin3, LOW); // turn LED OFF } else { digitalWrite(ledPin3, HIGH); // turn LED ON delay(200); digitalWrite(ledPin3, LOW); } void PlayTune();

{ // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 2; thisNote++) {

// to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1500 / noteDurations[thisNote]; tone(8, melody3[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); } } }

if (!digitalRead(3)) {

vall = digitalRead(inPin2); // read input value if (val == HIGH) { // check if the input is HIGH (button released) digitalWrite(ledPin2, LOW); // turn LED OFF } else { digitalWrite(ledPin2, HIGH); // turn LED ON delay(200); digitalWrite(ledPin2, LOW); } void PlayTune();

{ // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 2; thisNote++) {

// to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1500 / noteDurations[thisNote]; tone(8, melody2[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); } } } if (!digitalRead(2)) { val = digitalRead(inPin); // read input value if (val == HIGH) { // check if the input is HIGH (button released) digitalWrite(ledPin, LOW); // turn LED OFF } else { digitalWrite(ledPin, HIGH); // turn LED ON delay(200); digitalWrite(ledPin, LOW); } PlayTune(); } }

// a function that plays the tune void PlayTune() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 2; thisNote++) {

// to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1500 / noteDurations[thisNote]; tone(8, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); }

}

第 4 步:安装

 
 
 
 
pYYBAGOIpJqAetr8AAAS_uMfwRQ918.png
 
1 / 2
 

一切都完成了,只需要在桌子上为按钮/led 做一些孔(我用的烙铁可能不是最好的),然后把 arduino 粘在下面。

当您放置 arduino 和按钮时,请仔细考虑宝宝的腿不要弄断任何东西,就我而言,我用了一些纸板来保护

按钮

- 对于按钮,底部的电线连接到 arduino 上的引脚,另一根连接到 GND

引领:

  • 对于 LED,我将电阻器焊接到 LED,然后将所有 LED 的电阻器焊接到连接 GND 的一根导线
  • 实际上所有的 GND 都焊接到连接到 arduino 的 GND 的同一根线上

演讲者

一根电缆焊接到连接到 arduino 的电容器上

另一个焊料连接到 arduino 的 GND 的电线

第 5 步:结论

最烦人的是灯,当它发光时它们不够亮,我仍在寻找解决方案。

这是我的第一个 instrucables 期待您的反馈或改进椅子!

第 6 步:记忆游戏

当您的孩子长大后,您可以像Simon 所说的那样将游戏升级为更复杂的游戏

您不需要按钮的更改引脚,但是扬声器和 LED 不在正确的引脚上

您可以更改代码或更改引脚 13 上的扬声器

以及引脚 8、9、10、11 上的 LED。

#include 
Tone speakerpin;
int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4}; int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500}; int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5}; int duration[] = {100, 100, 100, 300, 100, 300}; boolean button[] = {2, 3, 4, 5}; //The four button input pins boolean ledpin[] = {8, 9, 10, 11}; // LED pins int turn = 0; // turn counter int buttonstate = 0; // button state checker int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far) int inputArray[100];

void setup() { Serial.begin(9600); speakerpin.begin(12); // speaker is on pin 13

for(int x=0; x<4; x++) // LED pins are outputs { pinMode(ledpin[x], OUTPUT); } for(int x=0; x<4; x++) { pinMode(button[x], INPUT); // button pins are inputs digitalWrite(button[x], HIGH); // enable internal pullup; buttons start in high position; logic reversed }

randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function for (int thisNote = 0; thisNote < 13; thisNote ++) { // play the next note: speakerpin.play(starttune[thisNote]); // hold the note: if (thisNote==0 || thisNote==2 || thisNote==4 || thisNote== 6) { digitalWrite(ledpin[0], HIGH); } if (thisNote==1 || thisNote==3 || thisNote==5 || thisNote== 7 || thisNote==9 || thisNote==11) { digitalWrite(ledpin[1], HIGH); } if (thisNote==8 || thisNote==12) { digitalWrite(ledpin[2], HIGH); } if (thisNote==10) { digitalWrite(ledpin[3], HIGH); } delay(duration2[thisNote]); // stop for the next note: speakerpin.stop(); digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); delay(25); } delay(1000); }

void loop() { for (int y=0; y<=99; y++) { //function for generating the array to be matched by the player digitalWrite(ledpin[0], HIGH); digitalWrite(ledpin[1], HIGH); digitalWrite(ledpin[2], HIGH); digitalWrite(ledpin[3], HIGH); for (int thisNote = 0; thisNote < 6; thisNote ++) { // play the next note: speakerpin.play(note[thisNote]); // hold the note: delay(duration[thisNote]); // stop for the next note: speakerpin.stop(); delay(25); } digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); delay(1000); for (int y=turn; y <= turn; y++) { //Limited by the turn variable Serial.println(""); //Some serial output to follow along Serial.print("Turn: "); Serial.print(y); Serial.println(""); randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turn count for (int x=0; x <= turn; x++) { Serial.print(randomArray[x]); for(int y=0; y<4; y++) { if (randomArray[x] == 1 && ledpin[y] == 8) { //if statements to display the stored values in the array digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_G3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); }

if (randomArray[x] == 2 && ledpin[y] == 9) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_A3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); } if (randomArray[x] == 3 && ledpin[y] == 10) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_B3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); }

if (randomArray[x] == 4 && ledpin[y] == 11) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_C4, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); } } } } input(); } }

void input() { //Function for allowing user input and checking input against the generated array

for (int x=0; x <= turn;) { //Statement controlled by turn count

for(int y=0; y<4; y++) { buttonstate = digitalRead(button[y]); if (buttonstate == LOW && button[y] == 2) { //Checking for button push digitalWrite(ledpin[0], HIGH); speakerpin.play(NOTE_G3, 100); delay(200); digitalWrite(ledpin[0], LOW); inputArray[x] = 1; delay(250); Serial.print(" "); Serial.print(1); if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against fail(); //the value in the same spot on the generated array } //The fail function is called if it does not match x++; } if (buttonstate == LOW && button[y] == 3) { digitalWrite(ledpin[1], HIGH); speakerpin.play(NOTE_A3, 100); delay(200); digitalWrite(ledpin[1], LOW); inputArray[x] = 2; delay(250); Serial.print(" "); Serial.print(2); if (inputArray[x] != randomArray[x]) { fail(); } x++; }

if (buttonstate == LOW && button[y] == 4) { digitalWrite(ledpin[2], HIGH); speakerpin.play(NOTE_B3, 100); delay(200); digitalWrite(ledpin[2], LOW); inputArray[x] = 3; delay(250); Serial.print(" "); Serial.print(3); if (inputArray[x] != randomArray[x]) { fail(); } x++; }

if (buttonstate == LOW && button[y] == 5) { digitalWrite(ledpin[3], HIGH); speakerpin.play(NOTE_C4, 100); delay(200); digitalWrite(ledpin[3], LOW); inputArray[x] = 4; delay(250); Serial.print(" "); Serial.print(4); if (inputArray[x] != randomArray[x]) { fail(); } x++; } } } delay(500); turn++; //Increments the turn count, also the last action before starting the output function over again }

void fail() { //Function used if the player fails to match the sequence

for (int y=0; y<=2; y++) { //Flashes lights for failure digitalWrite(ledpin[0], HIGH); digitalWrite(ledpin[1], HIGH); digitalWrite(ledpin[2], HIGH); digitalWrite(ledpin[3], HIGH); speakerpin.play(NOTE_G3, 300); delay(200); digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); speakerpin.play(NOTE_C3, 300); delay(200); } delay(500); turn = -1; //Resets turn value so the game starts over without need for a reset button }


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'Arduino UNO婴儿高脚椅音乐剧',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);