Difference between revisions of "Birthday Lamp Project (X02)"

From Microduino Wiki
Jump to: navigation, search
(Equipment)
(Program Description)
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[File:Happy Birthday Project.jpg|right|thumb|Birthday Light Project Build]]
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
==Overview==
+
=About=
 
Press the [[Crash]] switch and the [[Buzzer]] will play the Happy Birthday song. The LEDs will also flash. Double press the [[Crash]] switch to stop. This guide is written for the [[second generation mCookie kits]].
 
Press the [[Crash]] switch and the [[Buzzer]] will play the Happy Birthday song. The LEDs will also flash. Double press the [[Crash]] switch to stop. This guide is written for the [[second generation mCookie kits]].
 
[[File:birthday-light.jpg|600px|center]].
 
[[File:birthday-light.jpg|600px|center]].
  
==Schematic==
+
=Schematic=
 
The [[Core]] module detects if the [[Crash]] switch is pressed. The variable holding the status of the Crash switch will change to True if the switch is pressed and False if the switch is not pressed.  
 
The [[Core]] module detects if the [[Crash]] switch is pressed. The variable holding the status of the Crash switch will change to True if the switch is pressed and False if the switch is not pressed.  
  
Line 14: Line 15:
 
[[File:birthday-light-sch-E.jpg|600px|center]]
 
[[File:birthday-light-sch-E.jpg|600px|center]]
  
==Equipment==
+
=Equipment=
 
<div style="float:left; margin-right: 10px;">
 
<div style="float:left; margin-right: 10px;">
{|class="wikitable"
+
 
 +
{| class="wikitable" style="text-align:center;"  
 
|+ <center>For 102 Basic Kit</center>
 
|+ <center>For 102 Basic Kit</center>
!Module
+
! scope="col" style="width: 200px;" | Component
!Quantity
+
! scope="col" style="width: 100px;" | #
 +
|-
 +
|{{Clickable component|component_name=Core (ATmega328p)|link=MCookie-Core|image=File:MCookie-Core-rect.jpg}}
 +
|1
 
|-
 
|-
|[[Microduino-Core]]
+
| {{Clickable component|component_name=USBTTL|link=MCookie-USBTTL|image=File:MCookie--FT232-rect.jpg}}
 
|1
 
|1
 
|-
 
|-
|[[Microduino-Sensorhub]]
+
| {{Clickable component|component_name=LED Matrix|link=MCookie-LED_Matrix|image=file:MCookie-led-Matrix-rect.jpg}}
 
|1
 
|1
 
|-
 
|-
|[[Microduino-BUZZER]]
+
|{{Clickable component|component_name=Hub|link=mCookie-Hub|image=file:MCookie-Hub-rect.jpg}}
 
|1
 
|1
 
|-
 
|-
| [[Microduino-Colored LED]]
+
|{{Clickable component|component_name=Buzzer|link=Sensor-Buzzer|image=file:Microduino-BUZZER-v1.jpg}}
 
|1
 
|1
 +
|-
 +
| {{Clickable component|component_name=Crash Sensor|link=Sensor-Crash|image=file:Microduino_Crash-rect-v1.jpg}}
 +
|1
 +
|-
 +
| {{Clickable component|component_name=Sensor Cable}}
 +
| 2
 +
|-
 +
| {{Clickable component|component_name=MicroUSB Cable}}
 +
| 1
 
|}
 
|}
 
</div>
 
</div>
 
<div style="float:left; margin-right: 10px;">
 
<div style="float:left; margin-right: 10px;">
{|class="wikitable"
+
 
|+ <center>For 102 Basic Kit</center>
+
{| class="wikitable" style="text-align:center;"  
!Module
+
|+ <center>For 202 Advanced / 302 Expert Kits</center>
!Quantity
+
! scope="col" style="width: 200px;" | Component
 +
! scope="col" style="width: 100px;" | #
 +
|-
 +
|{{Clickable component|component_name=Core (ATmega328p)|link=MCookie-Core|image=File:MCookie-Core-rect.jpg}}
 +
|1
 +
|-
 +
| {{Clickable component|component_name=mBattery|link=MCookie-Battery|image=File:MBattery-rect.jpg}}
 +
|1
 
|-
 
|-
|[[Microduino-Core]]
+
| {{Clickable component|component_name=LED Matrix|link=MCookie-LED_Matrix|image=file:MCookie-led-Matrix-rect.jpg}}
 
|1
 
|1
 
|-
 
|-
|[[Microduino-Sensorhub]]
+
|{{Clickable component|component_name=Hub|link=mCookie-Hub|image=file:MCookie-Hub-rect.jpg}}
 
|1
 
|1
 
|-
 
|-
|[[Microduino-BUZZER]]
+
|{{Clickable component|component_name=Buzzer|link=Sensor-Buzzer|image=file:Microduino-BUZZER-v1.jpg}}
 
|1
 
|1
 
|-
 
|-
| [[Microduino-Colored LED]]
+
| {{Clickable component|component_name=Crash Sensor|link=Sensor-Crash|image=file:Microduino_Crash-rect-v1.jpg}}
 
|1
 
|1
 +
|-
 +
| {{Clickable component|component_name=Sensor Cable}}
 +
| 2
 +
|-
 +
| {{Clickable component|component_name=MicroUSB Cable}}
 +
| 1
 
|}
 
|}
 
</div>
 
</div>
 
<div style="clear:both">
 
<div style="clear:both">
[[File:music_birth.jpg|600px|center]]
 
  
==Preparation==
+
=Hardware Buildup=
*Setup 1: Connect CoreUSB and PC with USB cable, open Arduino IDE.  
+
'''NOTE''': When connecting sensor wires, push on the plastic connector and not on the wires. Pushing on the wire can damage them.
[[File:CoreUSB_Ble_pc.jpg|600px|center]]
+
#Connect the Buzzer to the Sensor Hub on Pin 6/7
*Setup 2: Click Files > Examples > mCookie > _101_BirthdayLight, download program. Or download:
+
#Connect the Crash sensor to the Sensor Hub on Pin 4/5
[[File: _101_BirthdayLight.jpg|600px|center]]
+
#Grab the mCookie USBTTL or mBattery and Stack the mCookie Core on top.
* Setup 3: Select the right board card and COM port, download program.  
+
#Stack the mCookie LED Matrix on top of that.
 +
#Stack the mCookie Sensor on top of that.
 +
#Plug in the MicroUSB cable to the mCookie USBTTL or mBattery to a computer.
 +
 
 +
=Program=
 +
1. Connect [[mCookie-Core|mCookie Core]] to the PC with the USB Cable. Open the Microduino IDE.
 +
 
 +
2. Download the project file and unzip: '''<big>[[File:Birthday_Lamp_X02.zip]]</big>'''.
 +
*Using the Microduino IDE and go to '''File > Open...''' and navigate to the unzipped folder. Open the '''Birthday_Lamp_X02.ino''' file.  
  
==Program description==
+
3. Select the board, processor and port:
 +
*Go to '''Tools > Board'''  and select '''Microduino/mCookie-Core (328p)'''
 +
*Go to '''Tools > Processor''' and select '''Atmega328P16M,5V'''
 +
*Go to '''Tools > Port''' and select the available port
 +
4. Upload the program by clicking on the '''right arrow icon''' on the top left of the window. Or under '''Sketch > Upload'''.
 +
 
 +
'''NOTE''': If not using the default Core module included in the kits, please follow the '''[[Selecting_board,_processor,_and_port|selecting the board and processor guide]]'''.
 +
==Program Description==
 
*Function
 
*Function
 
**"playNote()" Volume control  
 
**"playNote()" Volume control  
Line 70: Line 111:
 
*Define pin   
 
*Define pin   
 
<source lang="cpp">
 
<source lang="cpp">
#define PIXEL_PIN    A0 //Colored led
 
  
int key_Pin = 2;  //Key
+
#define PIXEL_PIN    A0    //Digital IO pin connected to the NeoPixels (LED Matrix)
int speakerPin = 6//Buzzer
+
 
 +
#define PIXEL_COUNT  6    //Number of NeoPixels in the LED Matrix
 +
 
 +
#define KEY_PIN      4    //Pin that the button (for play/pause) is connected to.
 +
 
 +
#define SPEAKER_PIN  6     //Pin that the buzzer is connected to.
 
</source>
 
</source>
  
 
*Check switch and see if it is pressed.
 
*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.  
+
**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".
 
**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">
 
<source lang="cpp">
 
void blink()
 
void blink()
 
{
 
{
   if (key_get(key_Pin, 0))  //Press the key  
+
   if (key_get(KEY_PIN, 0))  //Press the key  
 
   {
 
   {
 
     delay(200);  //Shockproof  
 
     delay(200);  //Shockproof  
Line 116: Line 161:
 
</source>
 
</source>
  
==Hardware Buildup==
+
==Debugging==
*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]]
+
==Tweaking==
*Setup 2: Connect the activated battery box to BM.  
+
 
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]
+
'''DEBUG''' un-comment or comment to disable or enable debug mode.
*Setup 3: Stack all modules together without fixed order and finish the hardware buildup.
+
 
[[File: music_birth_all.jpg|600px|center]]
+
'''PIXEL_PIN''' is the digital IO pin connected to the NeoPixels (LED Matrix).
* 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==
+
'''PIXEL_COUNT''' is number of NeoPixels in the LED Matrix or ColorLED string.
 +
 
 +
'''KEY_PIN''' is the pin that the button (for play/pause) is connected to.
 +
 
 +
'''SPEAKER_PIN''' is the pin in that the buzzer is connected to.
 +
 
 +
=Usage=
 
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.
 
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==
+
 
  
 
|}
 
|}

Latest revision as of 20:48, 1 May 2017

Birthday Light Project Build

About

Press the Crash switch and the Buzzer will play the Happy Birthday song. The LEDs will also flash. Double press the Crash switch to stop. This guide is written for the second generation mCookie kits.

Birthday-light.jpg
.

Schematic

The Core module detects if the Crash switch is pressed. The variable holding the status of the Crash switch will change to True if the switch is pressed and False if the switch is not pressed.

If True, the project will play the Happy Birthday music and light up.

If False, no music will play and the lights will be off.

Birthday-light-sch-E.jpg

Equipment

For 102 Basic Kit

Component #
MCookie-Core-rect.jpg
Core (ATmega328p)
1
MCookie--FT232-rect.jpg
USBTTL
1
MCookie-led-Matrix-rect.jpg
LED Matrix
1
MCookie-Hub-rect.jpg
Hub
1
Microduino-BUZZER-v1.jpg
Buzzer
1
Microduino Crash-rect-v1.jpg
Crash Sensor
1
Microduino-logo3.png
Sensor Cable
2
Microduino-logo3.png
MicroUSB Cable
1

For 202 Advanced / 302 Expert Kits

Component #
MCookie-Core-rect.jpg
Core (ATmega328p)
1
MBattery-rect.jpg
mBattery
1
MCookie-led-Matrix-rect.jpg
LED Matrix
1
MCookie-Hub-rect.jpg
Hub
1
Microduino-BUZZER-v1.jpg
Buzzer
1
Microduino Crash-rect-v1.jpg
Crash Sensor
1
Microduino-logo3.png
Sensor Cable
2
Microduino-logo3.png
MicroUSB Cable
1

Hardware Buildup

NOTE: When connecting sensor wires, push on the plastic connector and not on the wires. Pushing on the wire can damage them.

  1. Connect the Buzzer to the Sensor Hub on Pin 6/7
  2. Connect the Crash sensor to the Sensor Hub on Pin 4/5
  3. Grab the mCookie USBTTL or mBattery and Stack the mCookie Core on top.
  4. Stack the mCookie LED Matrix on top of that.
  5. Stack the mCookie Sensor on top of that.
  6. Plug in the MicroUSB cable to the mCookie USBTTL or mBattery to a computer.

Program

1. Connect mCookie Core to the PC with the USB Cable. Open the Microduino IDE.

2. Download the project file and unzip: File:Birthday Lamp X02.zip.

  • Using the Microduino IDE and go to File > Open... and navigate to the unzipped folder. Open the Birthday_Lamp_X02.ino file.

3. Select the board, processor and port:

  • Go to Tools > Board and select Microduino/mCookie-Core (328p)
  • Go to Tools > Processor and select Atmega328P16M,5V
  • Go to Tools > Port and select the available port

4. Upload the program by clicking on the right arrow icon on the top left of the window. Or under Sketch > Upload.

NOTE: If not using the default Core module included in the kits, please follow the selecting the board and processor guide.

Program Description

  • Function
    • "playNote()" Volume control
    • "colorSet()" Color control
    • "blink()" Judge if the key is pressed
  • Define pin
#define PIXEL_PIN     A0    //Digital IO pin connected to the NeoPixels (LED Matrix)

#define PIXEL_COUNT   6     //Number of NeoPixels in the LED Matrix

#define KEY_PIN       4     //Pin that the button (for play/pause) is connected to.

#define SPEAKER_PIN   6     //Pin that the buzzer is connected to.
  • 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
};

Debugging

Tweaking

DEBUG un-comment or comment to disable or enable debug mode.

PIXEL_PIN is the digital IO pin connected to the NeoPixels (LED Matrix).

PIXEL_COUNT is number of NeoPixels in the LED Matrix or ColorLED string.

KEY_PIN is the pin that the button (for play/pause) is connected to.

SPEAKER_PIN is the pin in that the buzzer is connected to.

Usage

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.


Retrieved from "https://wiki.microduinoinc.com/index.php?title=Birthday_Lamp_Project_(X02)&oldid=15782"