資料介紹
描述
如果沒有您一直在看,要讓嬰兒保持忙碌和安全絕非易事。
這個項目的目的是為所有年齡段的孩子創(chuàng)造一個有趣的高腳椅!
本教程的主要項目是設(shè)置一個游戲,當(dāng)寶寶按下按鈕時,同色燈亮并播放聲音
游戲可以很容易地變成更復(fù)雜的游戲,當(dāng)你的寶寶長大后,他們?nèi)匀粫娴瞄_心
和工作他們的記憶!
第 1 步:收集您的零件和工具
這個項目我們不需要太多東西,最昂貴的部分將是高腳椅。
我們會需要:
- Arduino UNO
- 4 街機(jī)按鈕45mm
- 4色led在這里
- 揚(yáng)聲器40 歐姆
- 10uf電容
- 連線這兩個在這里和這里都很有用
- 電阻 10k Ohms 5%這里
- 9v電池(或arduino的任何電源)
- 任何帶平板電腦的高腳椅都可以
- 一個寶寶
第 2 步:連接
在這一部分中,我們將看到將所有東西放在高腳椅上之前的項目模擬。
對于LED,負(fù)極連接到電阻器,正極連接到引腳。
一旦它工作,只需要用真正的按鈕和燈焊接所有東西
第 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 步:安裝
一切都完成了,只需要在桌子上為按鈕/led 做一些孔(我用的烙鐵可能不是最好的),然后把 arduino 粘在下面。
當(dāng)您放置 arduino 和按鈕時,請仔細(xì)考慮寶寶的腿不要弄斷任何東西,就我而言,我用了一些紙板來保護(hù)
按鈕:
- 對于按鈕,底部的電線連接到 arduino 上的引腳,另一根連接到 GND
引領(lǐng):
- 對于 LED,我將電阻器焊接到 LED,然后將所有 LED 的電阻器焊接到連接 GND 的一根導(dǎo)線
- 實際上所有的 GND 都焊接到連接到 arduino 的 GND 的同一根線上
演講者:
一根電纜焊接到連接到 arduino 的電容器上
另一個焊料連接到 arduino 的 GND 的電線
第 5 步:結(jié)論
最煩人的是燈,當(dāng)它發(fā)光時它們不夠亮,我仍在尋找解決方案。
這是我的第一個 instrucables 期待您的反饋或改進(jìn)椅子!
第 6 步:記憶游戲
當(dāng)您的孩子長大后,您可以像Simon 所說的那樣將游戲升級為更復(fù)雜的游戲。
您不需要按鈕的更改引腳,但是揚(yáng)聲器和 LED 不在正確的引腳上
您可以更改代碼或更改引腳 13 上的揚(yáng)聲器
以及引腳 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
}
- ARDUINO UNO案例之樂高積木盒
- 使用Arduino Uno的天文棺材舞蹈模因音樂
- Arduino嬰兒手機(jī)
- Arduino UNO構(gòu)建音樂播放器
- 如何將Arduino Uno安裝在面包板上來制作DIY Arduino Uno
- Arduino嬰兒保暖器
- Arduino Uno國內(nèi)改版電路原理圖下載 0次下載
- Arduino Uno Rev.3開發(fā)板意大利原版電路圖 0次下載
- 基于atmega8的arduino最小系統(tǒng)制作(arduino uno作為下載器)
- Arduino Files的Arduino Uno R3電路原理圖免費(fèi)下載 100次下載
- Arduino UNO的電路原理圖免費(fèi)下載 221次下載
- arduino uno電路設(shè)計原理圖 413次下載
- 倍福音樂劇劇場中的創(chuàng)新照明控制 14次下載
- arduino_Uno_Rev3-02-TH 0次下載
- Arduino_Uno_Rev3-schematic 60次下載
- 小安派-UNO-ET485 Arduino開發(fā)板簡介 751次閱讀
- 基于Arduino的音樂創(chuàng)作系統(tǒng)設(shè)計 959次閱讀
- 基于STM32單片機(jī)的嬰兒床控制系統(tǒng)設(shè)計 891次閱讀
- 這么漂亮的Arduino開發(fā)板你見過嗎? 1605次閱讀
- 嬰兒搖籃床播放器WT2003H音樂芯片方案 1272次閱讀
- 如何利用Arduino UNO和SD卡制作音樂播放器 7319次閱讀
- 如何使用Arduino Uno和HC-06實現(xiàn)智能手機(jī)對電燈的控制 4601次閱讀
- 基于Arduino UNO和HC-05藍(lán)牙模塊控制伺服電機(jī) 4824次閱讀
- 微雪電子Arduino開發(fā)板UNO PLUS簡介 5411次閱讀
- 微雪電子BB Black擴(kuò)展板|Arduino功能擴(kuò)展簡介 1502次閱讀
- 源創(chuàng)通信BPI-UNO32 arduino 開發(fā)板簡介 1590次閱讀
- dfrobotArduino UNO R3 介紹 6247次閱讀
- 詳解Arduino Uno控制直流電機(jī)之應(yīng)用 2w次閱讀
- 用Arduino Uno開發(fā)板和一塊面包板就能輕松搞定這一切 2.4w次閱讀
- 嬰兒監(jiān)測器(續(xù)) 3060次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊
- 1.06 MB | 532次下載 | 免費(fèi)
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費(fèi)
- 3TC358743XBG評估板參考手冊
- 1.36 MB | 330次下載 | 免費(fèi)
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費(fèi)
- 5元宇宙深度解析—未來的未來-風(fēng)口還是泡沫
- 6.40 MB | 227次下載 | 免費(fèi)
- 6迪文DGUS開發(fā)指南
- 31.67 MB | 194次下載 | 免費(fèi)
- 7元宇宙底層硬件系列報告
- 13.42 MB | 182次下載 | 免費(fèi)
- 8FP5207XR-G1中文應(yīng)用手冊
- 1.09 MB | 178次下載 | 免費(fèi)
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 2555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33566次下載 | 免費(fèi)
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費(fèi)
- 4開關(guān)電源設(shè)計實例指南
- 未知 | 21549次下載 | 免費(fèi)
- 5電氣工程師手冊免費(fèi)下載(新編第二版pdf電子書)
- 0.00 MB | 15349次下載 | 免費(fèi)
- 6數(shù)字電路基礎(chǔ)pdf(下載)
- 未知 | 13750次下載 | 免費(fèi)
- 7電子制作實例集錦 下載
- 未知 | 8113次下載 | 免費(fèi)
- 8《LED驅(qū)動電路設(shè)計》 溫德爾著
- 0.00 MB | 6656次下載 | 免費(fèi)
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費(fèi)
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537798次下載 | 免費(fèi)
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費(fèi)
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費(fèi)
- 6電路仿真軟件multisim 10.0免費(fèi)下載
- 340992 | 191187次下載 | 免費(fèi)
- 7十天學(xué)會AVR單片機(jī)與C語言視頻教程 下載
- 158M | 183279次下載 | 免費(fèi)
- 8proe5.0野火版下載(中文版免費(fèi)下載)
- 未知 | 138040次下載 | 免費(fèi)
評論
查看更多