Electronic Stopwatch

From Microduino Wiki
Revision as of 08:01, 4 November 2016 by Fengfeng (talk) (Created page with "{| style="width: 1000px;" |- | ==Overview== 600px|center Make a stopwatch which can time accurately, with one touch button controlling to sta...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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