Charles Tritt / Mbed OS 21_WhatTime_v5
Committer:
CSTritt
Date:
Fri Oct 01 03:12:23 2021 +0000
Revision:
111:2b4b5da72a15
Parent:
110:a930767c281c
First Mbed v. 5 version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 107:61b9c99a4e27 1 /*
CSTritt 111:2b4b5da72a15 2 Project: 21_WhatTime_v5
CSTritt 109:b061f9830736 3 File: main.cpp
CSTritt 110:a930767c281c 4
CSTritt 111:2b4b5da72a15 5 Uses a timer to display the interval between button press and release.
CSTritt 111:2b4b5da72a15 6
CSTritt 111:2b4b5da72a15 7 Created 12 Aug 2017 by Dr. Sheila Ross.
CSTritt 110:a930767c281c 8 Last modified 9/30/21 by C. S. Tritt (v. 1.0)
CSTritt 107:61b9c99a4e27 9 */
Jonathan Austin 0:2757d7abb7d9 10 #include "mbed.h"
CSTritt 110:a930767c281c 11
CSTritt 110:a930767c281c 12 // Construct a USER_BUTTON digital input.
CSTritt 110:a930767c281c 13 DigitalIn myButton(USER_BUTTON);
CSTritt 110:a930767c281c 14 // Construct a timer object.
CSTritt 110:a930767c281c 15 Timer myTimer;
CSTritt 110:a930767c281c 16 // Construct a transmit only serial connection over our USB.
CSTritt 110:a930767c281c 17 Serial pc(USBTX, NC, 9600);
CSTritt 111:2b4b5da72a15 18
CSTritt 109:b061f9830736 19 int main()
CSTritt 109:b061f9830736 20 {
CSTritt 110:a930767c281c 21 myTimer.start(); // Start the timer.
CSTritt 109:b061f9830736 22 while(true) { // Main loop.
CSTritt 111:2b4b5da72a15 23 if (myButton == 0) { // Button is pressed (its active low).
CSTritt 111:2b4b5da72a15 24 // Save the current timer value (state). uSs since reset.
CSTritt 111:2b4b5da72a15 25 float current_time = myTimer.read();
CSTritt 110:a930767c281c 26 // Send the time as text via the serial port.
CSTritt 111:2b4b5da72a15 27 pc.printf("Time difference %f seconds.\n",current_time );
CSTritt 111:2b4b5da72a15 28 myTimer.reset(); // Reset the timer.
CSTritt 111:2b4b5da72a15 29 while(myButton == 0) {} // Empty loop. Wait for button release.
CSTritt 108:eee3167b25b4 30 }
CSTritt 108:eee3167b25b4 31 }
CSTritt 108:eee3167b25b4 32 }