Music Alarm Clock

From Microduino Wiki
Jump to: navigation, search

Objective

Here we build a music alarm clock. You can control an alarm clock or set the alarm through a touch switch.

Principle

Detect two crash switches' press-down status: Short press or long press. For the key 1, you can shift the open or close of the alarm clock through long press and set the hour time via short press. For the key2, you can set to decrease the minute through long press or set to increase the minute by short press.

Equipment

Module Number Function
mCookie-CoreUSB 1 Core board
mCookie-Hub 1 Sensor pin board
mCookie-Audio 1 Audio module
mCookie-Amplifier 1 Amplifier module
mCookie-RTC 1 Clock module
Microduino-Crash 2 Crash sensor
  • Other Equipment:
    • Two loudspeakers
    • USB cable
Music boxz alarm module.jpg

Hardware Buildup

  • Setup1:Connect the two Crash sensors to the D4 and D6 of the mCookie-Hub.
Music boxz 4 6.JPG
  • Setup 2:Insert the TF card into the slot of the AudioShield module.
MusicBox Joystick TF.jpg
  • Setup 3:Stack the Audio and AudioShield together, connect them to a PC, and then you can play MP3 files under TF card root directory.
MusicBox Joystick song.jpg
  • Setup4:Connect the two loudspeakers to the Amplifier module.
MusicBox Joystick song speak.JPG
  • Setup5:Stack the Audio, AudioShield and Amplifier modules together.
MusicBox Joystick 3 speak.JPG
  • Setup6:Connect the activated battery box and the BM module.
CoreUSB Ble steup2.jpg
  • Setup7:Stack all modules without specific installation order(Except the Audio, AudioShield and Amplifier should be next to each other). By here, you have completed the circuit buildup.
MusicBox Crash steup ok.JPG

Code Download

File:Music clock.zip

Code Description

  • " audio.h " controls audio play.
  • OLED interface display
  • key_press() function detects press-down of the key.
  • Define clock time in "oled.h".
int alarm_hour = 19;
int alarm_minute = 45;
  • Define the tasks executed by long press and short press in "key". Users can define that freely.
  • Find " setRtcTime(15, 11, 13, 5, 17, 14, 00);" for time setting, which are "year", "month", "day", "week", "minute" and "second" respectively. Remove "//" while setting and download the code, then add "//" after that and download again, or it'll reset the time each time after power-off and on.

Result

You can use the crash switch to control the time as well as the status of the alarm clock. Since mCookie can be easily stacked with LEGO boards, you can build a beautiful shell for your project with LEGOs.

Video