查看“Music Box Light Control”的源代码
←
Music Box Light Control
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language| Music Box One(Light-sensitive version)}} {| style="width: 800px;" |- | ==Objective== We build a music box here. You can turn to different songs by opening the door of the box and shut the door to stop the music. ==Principle== We can detect the door's open or close via light-sensitive sensor. When opening the door, light is intense and it will trigger the change of songs or by closing the door, the music will be stopped. [[File:music_boxz-light.jpg|600px|center]] ==Equipment== {|class="wikitable" |- |Module||Number||Function |- |[[mCookie-CoreUSB]]||1||Core board |- |[[ mCookie-Hub]]||1||Sensor pin board |- |[[ mCookie-Audio]]||1||Audio module |- |[[ mCookie-Amplifier]]||1||Amplifier |- | [[mCookie-BM]]||1||Battery management |- | [[Microduino-Light]]||1||Light-sensitive sensor |} *Other Equipment: **Two loudspeakers **One cell of battery [[File:music_boxz.jpg|600px|center|thumb]] ==Preparation== *Setup 1:Connect CoreUSB and PC/MAC with a USB cable, then open Arduino IDE. [[File:CoreUSB_Ble_pc.jpg|600px|center]] * Setup 2: Download program examples: [https://github.com/Microduino/Microduino_Tutorials/tree/master/MCookie_Tutorial/music_box music_box_light] [[File: _MusicBox_light_ino.jpg|600px|center]] * Setup 3:Open downloaded program, select the right board and COM port, then click download. [[File: _MusicBox_light_ino-ok.jpg|600px|center]] ==Software Debugging== Code description: One part for detecting light intensity and the other part for sending serial instructions to control Audio playing, pause or cut according to brightness. *" audio.h " controls Audio file. *The use of Audio serial port is decided by jumper wires on the board. The default soft serial port is (2,3). <source lang="cpp"> #include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX #define AUDIO_PORT mySerial //#define AUDIO_PORT mySerial </source> *Pre-set photosensitive trigger value. When light-sensitive value is bigger than the pre-set value, the door will open or it'll close. Define pins of light-sensitive detection. <source lang="cpp"> #define light_cm 300 #define light_pin A0 </source> *When is detected value is bigger than pre-set value, it'll delay for 100 ms and then detect if the detected value is bigger than the pre-set value in case of shaking. If yes, then it'll execute cutting instruction " audio_down();". It'll execute instruction only once by True of False value of the "change". <source lang="cpp"> if ( light_val > light_cm && !change) { if (millis() - time1 > 100) { light_val = analogRead(light_pin); if (light_val > light_cm) { change = true;//True means the "if" condition will execute once. off = false; audio_down(); //audio_choose(1); //audio_play(); } time1 = millis(); } } </source> *When the detected value is small than the pre-set one, it'll delay for 100ms and re-detect. Then, it'll execute pause instruction " audio_pause();" and achieve instruction once by the True or False value of "off". <source lang="cpp"> if ( light_val > light_cm && !change) { if (millis() - time1 > 100) { light_val = analogRead(light_pin); if (light_val > light_cm) { change = true;//True means the "if" condition above can execute one time. off = false; audio_down(); //audio_choose(1); //audio_play(); } time1 = millis(); } } </source> ==Hardware Debugging== *Setup1:Connect the light-sensitive sensor to the A0 pin of Sensorhub. [[file: music_boxz _4_6.JPG|thumb|800px|center]] *Setup 2:Insert TF card into the slot of AudioShield. [[File: _MusicBox_Joystick _TF.jpg|600px|center]] *Setup 3:Stack Audio and AudioShield first, connect them to PC, then you can save MPS3 files into root directory of TF card. [[File: _MusicBox_Joystick _song.jpg|600px|center]] *Setup4:Connect two loudspeakers to Amplifier. [[file: MusicBox_Joystick _song_speak.JPG|600px|center]] *Setup5:Stack Audio, AudioShield and Amplifier together. [[file: MusicBox_Joystick _3_speak.JPG|600px|center]] *Setup6:Connect the activated battery box and BM. [[File:CoreUSB_Ble_steup2.jpg|600px|center]] *Setup7:Stack all modules without fixed order (Except that Audio, AudioShield and Amplifier should be together). [[file: MusicBox_light _steup_ok.JPG|600px|center]] ==Result== Open the music door and you can cut songs or close the door and stop the music. You can also build a beautiful LEGO shell since mCookie can be stacked with LEGO easily. [[file: music_boxz_light _legao.JPG|thumb|800px|center]] ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Music Box Light Control
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
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
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息