Difference between revisions of "Electronic Stopwatch"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 1000px;" |- | ==Overview== 600px|center Make a stopwatch which can time accurately, with one touch button controlling to sta...")
 
 
Line 45: Line 45:
 
==Program==
 
==Program==
 
===Required Program Blocks===
 
===Required Program Blocks===
*[[“OLED display-print” program block]]
+
*[["OLED display-print" program block]]
*[[“Touch button” program block]]
+
*[["Touch button" program block]]
*[[“Declare as”, “variable assignment” program block]]
+
*[["Declare as", "variable assignment" program block]]
*[[“Repeat doing” program block]]
+
*[["Repeat doing" program block]]
*[[“Time out begin” program block]]
+
*[["Time out begin" program block]]
*[[“Duration” program block]]
+
*[["Duration" program block]]
*[[“Calculate” program block]]
+
*[["Calculate" program block]]
*[[“Join” program block]]
+
*[["Join" program block]]
  
  
Line 64: Line 64:
 
Use variable to save the second number to display(in form of float).  
 
Use variable to save the second number to display(in form of float).  
 
Use variable s_timer to save the millisecond number read from the timer (in form of integer).  
 
Use variable s_timer to save the millisecond number read from the timer (in form of integer).  
Wait for the “start” button to be pressed.  
+
Wait for the "start" button to be pressed.  
 
Timer1 starts to time.  
 
Timer1 starts to time.  
 
[[File:mixly-ctrl-Stopwatch-code.jpg|600px|center]]
 
[[File:mixly-ctrl-Stopwatch-code.jpg|600px|center]]
Line 70: Line 70:
 
'''When the touch button 4 is free, repeat executing.'''
 
'''When the touch button 4 is free, repeat executing.'''
 
<br>
 
<br>
Repeat executing before the “stop” button is pressed.  
+
Repeat executing before the "stop" button is pressed.  
 
Save the value of timer1 into s_timer.
 
Save the value of timer1 into s_timer.
 
Divide s_timer by10(remove the last number, namely the 0.001).
 
Divide s_timer by10(remove the last number, namely the 0.001).
 
Save s_timer into s.
 
Save s_timer into s.
 
Divide s by 100(move the tenth and the percentile to the right of the decimal point).  
 
Divide s by 100(move the tenth and the percentile to the right of the decimal point).  
Display it in form of “s: second” on OLED.  
+
Display it in form of "s: second" on OLED.  
 
[[File:mixly-ctrl-Stopwatch-code1.jpg|600px|center]]
 
[[File:mixly-ctrl-Stopwatch-code1.jpg|600px|center]]
 
<br>
 
<br>
Line 81: Line 81:
 
'''Test the result'''
 
'''Test the result'''
 
<br>
 
<br>
After upload the program, press the touch button of pin 6 to start timing, and then you can see the time changing on OLED; press the touch button of pin 4, then the timing ends, the time won’t change any longer; press the touch button of pin 6 again, it will start another time.  
+
After upload the program, press the touch button of pin 6 to start timing, and then you can see the time changing on OLED; press the touch button of pin 4, then the timing ends, the time won't change any longer; press the touch button of pin 6 again, it will start another time.  
 
<br>
 
<br>
 
[[File:anywhere_Stopwatch.jpg|600px|center]]
 
[[File:anywhere_Stopwatch.jpg|600px|center]]
Line 93: Line 93:
 
Add these behind all programs.  
 
Add these behind all programs.  
 
<br>
 
<br>
Wait for the “reset” button to be pressed (after the end of timing, the start starts to serve as reset button).  
+
Wait for the "reset" button to be pressed (after the end of timing, the start starts to serve as reset button).  
Wait for the “reset” button to be released.  
+
Wait for the "reset" button to be released.  
 
Set the value of s to 0.  
 
Set the value of s to 0.  
 
Display the second number after reset on OLED.  
 
Display the second number after reset on OLED.  

Latest revision as of 08:52, 4 November 2016

Overview

Anywhere Stopwatch.jpg

Make a stopwatch which can time accurately, with one touch button controlling to start timing, and another controlling to stop timing, and display the time on OLED at the same time.
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
mCookie-OLED 1 Display
Touch button 2 Detect touch.

Other Equipment

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

Module Setup

Setup

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

Program

Required Program Blocks


Programming Thought

When the start is pressed, it begins to time. Not until the stop button is pressed are the calculating time and display programs executed repeatedly. When the stop button is pressed, stop timing, the current time is kept on the screen.

Mixly-ctrl-Stopwatch.jpg

Start to Program

Declare a variable, wait for the touch button to be pressed, and then start to time.
Use variable to save the second number to display(in form of float). Use variable s_timer to save the millisecond number read from the timer (in form of integer). Wait for the "start" button to be pressed. Timer1 starts to time.

Mixly-ctrl-Stopwatch-code.jpg


When the touch button 4 is free, repeat executing.
Repeat executing before the "stop" button is pressed. Save the value of timer1 into s_timer. Divide s_timer by10(remove the last number, namely the 0.001). Save s_timer into s. Divide s by 100(move the tenth and the percentile to the right of the decimal point). Display it in form of "s: second" on OLED.

Mixly-ctrl-Stopwatch-code1.jpg



Test the result
After upload the program, press the touch button of pin 6 to start timing, and then you can see the time changing on OLED; press the touch button of pin 4, then the timing ends, the time won't change any longer; press the touch button of pin 6 again, it will start another time.

Anywhere Stopwatch.jpg



Q: How to reset the data in the stopwatch?
A. After the end of timing, assign 0 to the variable to store time.

Add these behind all programs.
Wait for the "reset" button to be pressed (after the end of timing, the start starts to serve as reset button). Wait for the "reset" button to be released. Set the value of s to 0. Display the second number after reset on OLED.

Mixly-ctrl-Stopwatch-code2.jpg

Technical Specification

Related Cases


FAQ