Difference between revisions of "Birthday Lamp"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{{Language| Birthday Lantern}} {| style="width: 800px;" |- | ==Objective== To make a birthday lantern, press the button and play the music via a buzzer and you can see flashin...")
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Language| Birthday Lantern}}
+
{{Language| Birthday Lamp}}
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
==Objective==
+
==Overview==
To make a birthday lantern, press the button and play the music via a buzzer and you can see flashing lamp.  
+
Press switch, the buzzer will play pre-set Happy Birthday song and at the same time, the lamp will shine. Double press the key, it'll stop.   
 +
[[File:birthday-light.jpg|600px|center]]
  
==Principle==
+
==Schematic==
 +
System can detect if the crash switch is collided. If yes, the status including True and False will change once. When it is True, the device will play music and get lighted. conversely, it'll stop playing music and turn off the light.
 +
[[File:birthday-light-sch-E.jpg|600px|center]]
  
==Device==
+
==Equipment==
 
{|class="wikitable"
 
{|class="wikitable"
 
|-
 
|-
 
|Module||Number||Function
 
|Module||Number||Function
 
|-
 
|-
|[[Microduino-CoreUSB]]||1||Core board
+
|[[Microduino-CoreUSB]]||1||Core board  
 
|-
 
|-
|[[Microduino-Sensorhub]]||1||Sensor pinboard
+
|[[Microduino-Sensorhub]]||1||Sensor pin board
 
|-
 
|-
|[[Microduino-BM]]||1||Buttery 
+
|[[Microduino-BM]]||1||Battery
 
|-
 
|-
|[[Microduino-BUZZER]]||1|| Buzzer
+
|[[Microduino-BUZZER]]||1||Buzzer
 
|-
 
|-
| [[Microduino-Lantern]]||1||colored light  
+
| [[Microduino-Colored LED]]||1||Colored light  
 
|}
 
|}
*Other
+
[[File:music_birth.jpg|600px|center]]
**Battery
 
[[File:music_birth.jpg|600px|center|thumb]]
 
  
== Hardware Building==
+
==Preparation==
*Setup 1:Stack CoreUSB and Sensorhub.  
+
*Setup 1: Connect CoreUSB and PC with USB cable, open Arduino IDE.  
[[File:CoreUSB_Sensorhub.jpg|600px|center|thumb]]
+
[[File:CoreUSB_Ble_pc.jpg|600px|center]]
*Setup 2:Connect Buzzer to the D6 pin of Sensorhub, the Colored led to A0 and the crash switch to D2.
+
*Setup 2: Click Files > Examples > mCookie > _101_BirthdayLight, download program. Or download:  
[[file:Microduino-sensorhub_rule.JPG|thumb|800px|center]]
+
[[File: _101_BirthdayLight.jpg|600px|center]]
[[File: music_birth_all.jpg|600px|center|thumb]]
+
* Setup 3: Select the right board card and COM port, download program.
  
==Software Debugging==
+
==Program description==
*Setup 1:Start programing. Build development environment and download program code.
+
*Function
[https://github.com/Microduino/Microduino_Tutorials/blob/master/MCookie_Tutorial/music_birth/music_birth.ino music_birth]
+
**"playNote()" Volume control  
*Setup 2:Code description 
+
**"colorSet()" Color control
*Function  
+
**"blink()" Judge if the key is pressed
**“playNote()”Sound control  
+
*Define pin 
**“colorSet()”Color control
 
**“blink()”Pause 
 
*Pin description
 
 
<source lang="cpp">
 
<source lang="cpp">
#define PIXEL_PIN    A0 //Colored light
+
#define PIXEL_PIN    A0 //Colored led
  
 
int key_Pin = 2;  //Key  
 
int key_Pin = 2;  //Key  
int speakerPin = 6;  //Buzzer  
+
int speakerPin = 6;  //Buzzer
 
</source>
 
</source>
*Light change (Red, green, blue and yellow)  
+
 
 +
*Check switch and see if it is pressed.
 +
**Use file " key_get(key_Pin, 0)" to detect if the key is pressed. " key_Pin " is the pin that connects with the key, which can be change by users. "0" means triggering once pressing the key. "1" means triggering after you press and loosen the key.
 +
**Each time the key is detected to be "pressed", the True and False values of " play_pause " will change once. Therefore, you can control the music and light according to the values of "play_pause".
 +
<source lang="cpp">
 +
void blink()
 +
{
 +
  if (key_get(key_Pin, 0))  //Press the key
 +
  {
 +
    delay(200);  //Shockproof
 +
    play_pause = !play_pause; // Status changes one time.
 +
  }
 +
}
 +
</source>
 +
*Light change (Red-green-blue-yellow)  
 +
**"colorSet(strip.Color(R, G,B));" R, G and B are three primary colors. Users can change that according to personal needs.
 
<source lang="cpp">
 
<source lang="cpp">
      if (add == 1)
+
add++;
        colorSet(strip.Color(i * 10, 0, 0));
+
if (add == 5)
      else if (add == 2)
+
add = 1;
        colorSet(strip.Color(0, i * 10, 0));
+
if (add == 1)
      else if (add == 3)
+
colorSet(strip.Color(i * 10, 0, 0));
        colorSet(strip.Color(0, 0, i * 10));
+
else if (add == 2)
      else if (add == 4)
+
colorSet(strip.Color(0, i * 10, 0));
        colorSet(strip.Color(i * 10, i * 10, 0));
+
else if (add == 3)
 +
colorSet(strip.Color(0, 0, i * 10));
 +
else if (add == 4)
 +
colorSet(strip.Color(i * 10, i * 10, 0));
 
</source>
 
</source>
 +
 
*Play music  
 
*Play music  
 +
**Save fixed notes and change the pitch in program definition.
 
<source lang="cpp">
 
<source lang="cpp">
      if (!play_pause)
+
int notes[] = {
      {
+
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_F4, NOTE_E4,
        play_pause = false;
+
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_G4, NOTE_F4,
        noTone(speakerPin);
+
  NOTE_C4, NOTE_C4, NOTE_C5, NOTE_A4, NOTE_F4, NOTE_E4, NOTE_D4,
        return;
+
  NOTE_AS4, NOTE_AS4, NOTE_A4, NOTE_F4, NOTE_G4, NOTE_F4
      }
+
};
      playNote(notes[i], beats[i]); // make sound
 
 
</source>
 
</source>
 +
 +
==Hardware Buildup==
 +
*Setup 1: Connect Buzzer to D6 pin of Sensorhub and Colored LED to A0, crash switch to D4.
 +
[[File:CoreUSB_Sensorhub_BirthdayLight_E.jpg|600px|center]]
 +
*Setup 2: Connect the activated battery box to BM.
 +
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]
 +
*Setup 3: Stack all modules together without fixed order and finish the hardware buildup.
 +
[[File: music_birth_all.jpg|600px|center]]
 +
* Setup 4: DIY your LEGO birthday lamp.
 +
[[File: music_birth_over.jpg|600px|center]]
 +
If modules do not work normally, please try to cut off and power supply and restart it.
 +
[[File: music_birth_over1.jpg|600px|center]]
  
 
==Result==
 
==Result==
Press the crash switch, it will play music and the lights start flashing and turning brighter. Press the key again, it will turn off the music and the light.  
+
Press crash switch, play birthday song and get lighted. The light will get brighter and brighter. Then press the switch once more, the music and light will be turned off.
 
 
 
==Video==
 
==Video==
  
 
|}
 
|}

Latest revision as of 06:51, 30 September 2016

Language: English  • 中文

Overview

Press switch, the buzzer will play pre-set Happy Birthday song and at the same time, the lamp will shine. Double press the key, it'll stop.

Birthday-light.jpg

Schematic

System can detect if the crash switch is collided. If yes, the status including True and False will change once. When it is True, the device will play music and get lighted. conversely, it'll stop playing music and turn off the light.

Birthday-light-sch-E.jpg

Equipment

Module Number Function
Microduino-CoreUSB 1 Core board
Microduino-Sensorhub 1 Sensor pin board
Microduino-BM 1 Battery
Microduino-BUZZER 1 Buzzer
Microduino-Colored LED 1 Colored light
Music birth.jpg

Preparation

  • Setup 1: Connect CoreUSB and PC with USB cable, open Arduino IDE.
CoreUSB Ble pc.jpg
  • Setup 2: Click Files > Examples > mCookie > _101_BirthdayLight, download program. Or download:
101 BirthdayLight.jpg
  • Setup 3: Select the right board card and COM port, download program.

Program description

  • Function
    • "playNote()" Volume control
    • "colorSet()" Color control
    • "blink()" Judge if the key is pressed
  • Define pin
#define PIXEL_PIN    A0 //Colored led 

int key_Pin = 2;  //Key 
int speakerPin = 6;  //Buzzer
  • Check switch and see if it is pressed.
    • Use file " key_get(key_Pin, 0)" to detect if the key is pressed. " key_Pin " is the pin that connects with the key, which can be change by users. "0" means triggering once pressing the key. "1" means triggering after you press and loosen the key.
    • Each time the key is detected to be "pressed", the True and False values of " play_pause " will change once. Therefore, you can control the music and light according to the values of "play_pause".
void blink()
{
  if (key_get(key_Pin, 0))  //Press the key 
  {
    delay(200);  //Shockproof 
    play_pause = !play_pause; // Status changes one time. 
  }
}
  • Light change (Red-green-blue-yellow)
    • "colorSet(strip.Color(R, G,B));" R, G and B are three primary colors. Users can change that according to personal needs.
add++;
if (add == 5)
add = 1;
if (add == 1)
colorSet(strip.Color(i * 10, 0, 0));
else if (add == 2)
colorSet(strip.Color(0, i * 10, 0));
else if (add == 3)
colorSet(strip.Color(0, 0, i * 10));
else if (add == 4)
colorSet(strip.Color(i * 10, i * 10, 0));
  • Play music
    • Save fixed notes and change the pitch in program definition.
int notes[] = {
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_F4, NOTE_E4,
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_G4, NOTE_F4,
  NOTE_C4, NOTE_C4, NOTE_C5, NOTE_A4, NOTE_F4, NOTE_E4, NOTE_D4,
  NOTE_AS4, NOTE_AS4, NOTE_A4, NOTE_F4, NOTE_G4, NOTE_F4
};

Hardware Buildup

  • Setup 1: Connect Buzzer to D6 pin of Sensorhub and Colored LED to A0, crash switch to D4.
CoreUSB Sensorhub BirthdayLight E.jpg
  • Setup 2: Connect the activated battery box to BM.
CoreUSB Ble steup2.jpg
  • Setup 3: Stack all modules together without fixed order and finish the hardware buildup.
Music birth all.jpg
  • Setup 4: DIY your LEGO birthday lamp.
Music birth over.jpg

If modules do not work normally, please try to cut off and power supply and restart it.

Result

Press crash switch, play birthday song and get lighted. The light will get brighter and brighter. Then press the switch once more, the music and light will be turned off.

Video