<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
		<id>http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Music_Box_Light_Control</id>
		<title>Music Box Light Control - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Music_Box_Light_Control"/>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Music_Box_Light_Control&amp;action=history"/>
		<updated>2026-06-06T05:19:30Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https//wiki.microduino.cn/index.php?title=Music_Box_Light_Control&amp;diff=10892&amp;oldid=prev</id>
		<title>1304410487@qq.com：Created page with &quot;{{Language| Music Box One(Light-sensitive version)}} {| style=&quot;width: 800px;&quot; |- | ==Objective== We build a music box here. You can turn to different songs by opening the door...&quot;</title>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Music_Box_Light_Control&amp;diff=10892&amp;oldid=prev"/>
				<updated>2015-10-20T09:27:18Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Language| Music Box One(Light-sensitive version)}} {| style=&amp;quot;width: 800px;&amp;quot; |- | ==Objective== We build a music box here. You can turn to different songs by opening the door...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Language| Music Box One(Light-sensitive version)}}&lt;br /&gt;
{| style=&amp;quot;width: 800px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
==Objective==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Principle==&lt;br /&gt;
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. &lt;br /&gt;
[[File:music_boxz-light.jpg|600px|center]]&lt;br /&gt;
&lt;br /&gt;
==Equipment==&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|Module||Number||Function&lt;br /&gt;
|-&lt;br /&gt;
|[[mCookie-CoreUSB]]||1||Core board&lt;br /&gt;
|-&lt;br /&gt;
|[[ mCookie-Hub]]||1||Sensor pin board &lt;br /&gt;
|-&lt;br /&gt;
|[[ mCookie-Audio]]||1||Audio module&lt;br /&gt;
|-&lt;br /&gt;
|[[ mCookie-Amplifier]]||1||Amplifier&lt;br /&gt;
|-&lt;br /&gt;
| [[mCookie-BM]]||1||Battery management &lt;br /&gt;
|-&lt;br /&gt;
| [[Microduino-Light]]||1||Light-sensitive sensor &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Other Equipment: &lt;br /&gt;
**Two loudspeakers &lt;br /&gt;
**One cell of battery &lt;br /&gt;
&lt;br /&gt;
 [[File:music_boxz.jpg|600px|center|thumb]]&lt;br /&gt;
==Preparation==&lt;br /&gt;
*Setup 1：Connect CoreUSB and PC/MAC with a USB cable, then open Arduino IDE. &lt;br /&gt;
[[File:CoreUSB_Ble_pc.jpg|600px|center]]&lt;br /&gt;
* Setup 2:&lt;br /&gt;
Download program examples: &lt;br /&gt;
[https://github.com/Microduino/Microduino_Tutorials/tree/master/MCookie_Tutorial/music_box music_box_light]&lt;br /&gt;
[[File: _MusicBox_light_ino.jpg|600px|center]]&lt;br /&gt;
* Setup 3：Open downloaded program, select the right board and COM port, then click download. &lt;br /&gt;
&lt;br /&gt;
[[File: _MusicBox_light_ino-ok.jpg|600px|center]]&lt;br /&gt;
==Software Debugging==&lt;br /&gt;
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. &lt;br /&gt;
*&amp;quot; audio.h &amp;quot; controls Audio file. &lt;br /&gt;
*The use of Audio serial port is decided by jumper wires on the board. The default soft serial port is (2,3).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SoftwareSerial.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SoftwareSerial mySerial(2, 3); // RX, TX&lt;br /&gt;
&lt;br /&gt;
#define AUDIO_PORT mySerial   &lt;br /&gt;
//#define AUDIO_PORT mySerial  &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*Pre-set photosensitive trigger value. When light-sensitive value is bigger than the pre-set value, the door will open or it'll close. &lt;br /&gt;
Define pins of light-sensitive detection.   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#define light_cm 300&lt;br /&gt;
&lt;br /&gt;
#define light_pin A0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*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 &amp;quot; audio_down();&amp;quot;. It'll execute instruction only once by True of False value of the &amp;quot;change&amp;quot;.  &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  if ( light_val &amp;gt; light_cm &amp;amp;&amp;amp; !change)&lt;br /&gt;
  {&lt;br /&gt;
    if (millis() - time1 &amp;gt; 100)&lt;br /&gt;
    {&lt;br /&gt;
      light_val = analogRead(light_pin);&lt;br /&gt;
      if (light_val &amp;gt; light_cm)&lt;br /&gt;
      {&lt;br /&gt;
        change = true;//True means the &amp;quot;if&amp;quot; condition will execute once. &lt;br /&gt;
        off = false;&lt;br /&gt;
        audio_down();&lt;br /&gt;
        //audio_choose(1);&lt;br /&gt;
        //audio_play();&lt;br /&gt;
      }&lt;br /&gt;
      time1 = millis();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*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 &amp;quot; audio_pause();&amp;quot; and achieve instruction once by the True or False value of &amp;quot;off&amp;quot;.  &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  if ( light_val &amp;gt; light_cm &amp;amp;&amp;amp; !change)&lt;br /&gt;
  {&lt;br /&gt;
    if (millis() - time1 &amp;gt; 100)&lt;br /&gt;
    {&lt;br /&gt;
      light_val = analogRead(light_pin);&lt;br /&gt;
      if (light_val &amp;gt; light_cm)&lt;br /&gt;
      {&lt;br /&gt;
        change = true;//True means the &amp;quot;if&amp;quot; condition above can execute one time. &lt;br /&gt;
        off = false;&lt;br /&gt;
        audio_down();&lt;br /&gt;
        //audio_choose(1);&lt;br /&gt;
        //audio_play();&lt;br /&gt;
      }&lt;br /&gt;
      time1 = millis();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hardware Debugging==&lt;br /&gt;
*Setup1：Connect the light-sensitive sensor to the A0 pin of Sensorhub. &lt;br /&gt;
 [[file: music_boxz _4_6.JPG|thumb|800px|center]]&lt;br /&gt;
*Setup 2：Insert TF card into the slot of AudioShield. &lt;br /&gt;
[[File: _MusicBox_Joystick _TF.jpg|600px|center]]&lt;br /&gt;
*Setup 3：Stack Audio and AudioShield first, connect them to PC, then you can save MPS3 files into root directory of TF card. &lt;br /&gt;
[[File: _MusicBox_Joystick _song.jpg|600px|center]]&lt;br /&gt;
*Setup4：Connect two loudspeakers to Amplifier. &lt;br /&gt;
[[file: MusicBox_Joystick _song_speak.JPG|600px|center]]&lt;br /&gt;
*Setup5：Stack Audio, AudioShield and Amplifier together. &lt;br /&gt;
[[file: MusicBox_Joystick _3_speak.JPG|600px|center]]&lt;br /&gt;
*Setup6：Connect the activated battery box and BM. &lt;br /&gt;
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]&lt;br /&gt;
*Setup7：Stack all modules without fixed order (Except that Audio, AudioShield and Amplifier should be together). &lt;br /&gt;
[[file: MusicBox_light _steup_ok.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[file: music_boxz_light _legao.JPG|thumb|800px|center]]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>1304410487@qq.com</name></author>	</entry>

	</feed>