Difference between revisions of "Countdown Alarm Clock"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 1000px;" |- | ==Outline== 600px|center Let’s make an alarm clock of which the countdown time can be set, and it can ring at th...")
 
 
Line 6: Line 6:
 
[[File:anywhere_alarm.jpg|600px|center]]
 
[[File:anywhere_alarm.jpg|600px|center]]
  
Let’s make an alarm clock of which the countdown time can be set, and it can ring at the end of the countdown.  
+
Let's make an alarm clock of which the countdown time can be set, and it can ring at the end of the countdown.  
 
<br>
 
<br>
 
Suitable kits: mCookie302
 
Suitable kits: mCookie302
Line 45: Line 45:
 
==Programming==
 
==Programming==
 
===Required Program Blocks===
 
===Required Program Blocks===
*[[“Repeat doing” program block]]
+
*[["Repeat doing" program block]]
*[[“Declare as”, “item” program block]]
+
*[["Declare as", "item" program block]]
*[[“Touch button” program block]]
+
*[["Touch button" program block]]
*[[“Waiting”program block]]
+
*[["Waiting" program block]]
*[[“Delay”program block]]
+
*[["Delay" program block]]
*[[“Buzzer on-melody” program block]]
+
*[["Buzzer on-melody" program block]]
*[[“Println” program block]]
+
*[["Println" program block]]
*[[“Calculate”program block]]
+
*[["Calculate" program block]]
*[[“Text” program block]]
+
*[["Text" program block]]
*[[“Join” program block]]
+
*[["Join" program block]]
  
 
===Programming Thought===
 
===Programming Thought===
Line 74: Line 74:
 
'''Start the countdown. After then end of time, the buzzer rings. '''
 
'''Start the countdown. After then end of time, the buzzer rings. '''
 
<br>
 
<br>
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.  
+
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.  
 
[[File:mixly-ctrl-alarm-code1.jpg|600px|center]]
 
[[File:mixly-ctrl-alarm-code1.jpg|600px|center]]
 
'''Wait for the touch button 6 to be pressed again, then turn the buzzer off.'''
 
'''Wait for the touch button 6 to be pressed again, then turn the buzzer off.'''
Line 89: Line 89:
 
<br>
 
<br>
 
<br>
 
<br>
Q: Although we have implemented the countdown, we can’t see the process of it, how can we see the subtraction of time?  
+
Q: Although we have implemented the countdown, we can't see the process of it, how can we see the subtraction of time?  
 
<br>
 
<br>
 
A: Each time of the time subtracting 1s, print it out, so that we can see the time on the serial monitor.  
 
A: Each time of the time subtracting 1s, print it out, so that we can see the time on the serial monitor.  
Line 100: Line 100:
 
'''Display the countdown process, and the buzzer will ring at the end of that. '''
 
'''Display the countdown process, and the buzzer will ring at the end of that. '''
 
<br>
 
<br>
Use every time program block. Because it is countdown, the execution time is from timeto 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.
+
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.
 
[[File:mixly-ctrl-alarm-code4.jpg|600px|center]]
 
[[File:mixly-ctrl-alarm-code4.jpg|600px|center]]
  

Latest revision as of 10:18, 13 October 2016

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