查看“Buzzer Alarm”的源代码
←
Buzzer Alarm
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Purpose== This course will show you how to use Microduino buzzer to play simple songs. ==Equipment== *'''[[Microduino-CoreUSB]]''' *'''[[Microduino-BUZZER]]''' *'''[[Microduino-Sensorhub]]''' *Other Hardware Equipment **1x USB cable ==Buzzer Description== Buzzer includes active buzzer and passive buzzer. Active buzzer has polarity like LED diodes, whose long pin connects to VCC and the short pin to GND. With that connection, active buzzer can make continuous sounds. The passive buzzer has no polarity. With three pins consisting of two power pins and an audio input pin, the passive buzzer can only make sound in audio output circuit. In this experiment, we will use a passive buzzer. ==Program== *Program code <source lang="cpp"> int song[] ={ 262,262,294,262,349,330, 262,262,294,262,392,349, 262,262,523,440,349,330,294, 494,494,440,349,392,349 }; int noteDurations[] = { 4,4,2,2,2,1, 4,4,2,2,2,1, 4,4,2,2,2,2,2, 4,4,2,2,2,1 }; void setup() { for (int thisNote = 0; thisNote<25;thisNote++) { int noteDuration = 1000/noteDurations[thisNote]; tone(8, song[thisNote],noteDuration); int pauseBetweenNotes = noteDuration *1.30; delay(pauseBetweenNotes); noTone(8); } } void loop() { setup(); } </source> *Function description The music coming from Arduino board is controlled by tone(). The change of the function can change the rhythm of the music. The code includes two forms—tone(pin, frequency, duration) and tone(pin, frequency). <br> * In the first function, “pin” represents the pin that connects to a loud speaker.<br> * If using the second function, then you also need noTone() to control the music. ==Debugging== Step 1: Insert Microduino buzzer to D8 pin of Microduino-Sensorhub. [[File:MicroduinoBuzzerSensor.png|600px|center|thumb]] Step 2: Connect your PC with USB cable, download the code and program it to Microduino-CoreUSB. [[File:MicroduinoBuzzerSensor1.png|600px|center|thumb]] Step 3: Power on and you’ll hear the music. [[File:MicroduinoBuzzerSensor2.png|600px|center|thumb]] ==Result== You can use the buzzer to play music.
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Buzzer Alarm
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息