Countdown Alarm Clock

From Microduino Wiki
Revision as of 10:18, 13 October 2016 by Fengfeng (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Outline

Anywhere alarm.jpg

Let's make an alarm clock of which the countdown time can be set, and it can ring at the end of the countdown.
Suitable kits: mCookie302


Module Bill

Module

Module Number Function
mCookie-Core 1 Core board
Battery box 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
Touch button 3 Detect the touch
Buzzer 1 Produce sound

Other Equipment

  • USB cable*1
  • Sensor cable*4
  • Sensor shell*1
  • Lego or other fixation structure
Anywhere alarm-module.jpg

Module Setup

Setup

Anywhere alarm-step.jpg
  • Assemble the modules and sensors:
    • Stick the red core module, battery base and green extension module together;
    • Connect the buzzer to pin 8/9 of Hub;
    • Connect the 3 touch buttons to pin 6/7, 4/5, and 2/3 of Hub respectively;
    • Insert one end of USB cable into the battery base and connect the other to computer;

Programming

Required Program Blocks

Programming Thought

Choose 3 touch buttons, one to control the set, start and end of the countdown, another to set the time addition of the countdown, and another to set the subtraction of the countdown.

Mixly-ctrl-alarm.jpg

Start to Program

Declare as. After the touch button 6 is released, repeat executing the time set program.
Declare a variable named time, to save the second number of the countdown.
When the touch button 6 is released, repeat executing the internal program(detect the button time + and -).


If touch button 4 is pressed(time reduces by 1s, wait for the button to be released, and send the changed time to computer).
If touch button 2 is pressed(time increases by 1s, wait for the button to be released, and send the changed time to computer).

Mixly-ctrl-alarm-code.jpg

Start the countdown. After then end of time, the buzzer rings.
Send "start" to computer, representing the countdown starts. Make the second number saved in variable time multiply 1000(ms), and delay, then send "alarm!" to computer, representing the time is over.

Mixly-ctrl-alarm-code1.jpg

Wait for the touch button 6 to be pressed again, then turn the buzzer off.
Before the touch button 6 is pressed, the buzzer will keep buzzing all the time. Wait for the touch button 6 to be released, to prevent mistaken judgment.

Mixly-ctrl-alarm-code2.jpg



Test the result
After upload, before the touch button 6 is pressed, you can set the time, pressing touch button 4 to decrease time, pressing button 2 to increase time. Open the serial monitor, and you can see the time. After that, press the touch button 6, and the countdown will start. At the end of the countdown, the buzzer will ring. Press button 6 again, then the buzzer will go off.

Anywhere alarm.jpg



Q: Although we have implemented the countdown, we can't see the process of it, how can we see the subtraction of time?
A: Each time of the time subtracting 1s, print it out, so that we can see the time on the serial monitor.

Declare a variable time. Release the touch button 6, and set the countdown time.
Press the touch button 4 , and the time adds 1; press button 2, and the time subtracts 1.

Mixly-ctrl-alarm-code3.jpg

Display the countdown process, and the buzzer will ring at the end of that.
Use every time program block. Because it is countdown, the execution time is from time to 1, and the step is -1. During each execution, reduce the variable time by 1, and send the second number saved in time to computer, and then delay 1s.

Mixly-ctrl-alarm-code4.jpg


Technical Specification

Related Cases

FAQ