Birthday Lamp Project (X02)

From Microduino Wiki
Revision as of 19:01, 28 December 2016 by Sonny (talk) (Preparation)
Jump to: navigation, search

Overview

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
Music birth.jpg

Preparation

  1. Connect Core to the PC with the USB Cable. Open the Microduino IDE.
CoreUSB Ble pc.jpg
  1. Setup 2: Go to File > Examples > 00.mCookie > _101_BirthdayLight
101 BirthdayLight.jpg
  1. Setup 3: Select

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

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