Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@110:a930767c281c, 2021-10-01 (annotated)
- Committer:
- CSTritt
- Date:
- Fri Oct 01 03:05:20 2021 +0000
- Revision:
- 110:a930767c281c
- Parent:
- 109:b061f9830736
- Child:
- 111:2b4b5da72a15
First Mbed v. 5 version.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| CSTritt | 107:61b9c99a4e27 | 1 | /* | 
| CSTritt | 110:a930767c281c | 2 | Project: 21_TimerTest2_v5 | 
| CSTritt | 109:b061f9830736 | 3 | File: main.cpp | 
| CSTritt | 110:a930767c281c | 4 | |
| CSTritt | 110:a930767c281c | 5 | Tests timer peformance. Display new time difference with each button press | 
| CSTritt | 110:a930767c281c | 6 | and release. Differences of 4 or 5 microseconds are typical. | 
| CSTritt | 109:b061f9830736 | 7 | |
| 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 | |
| CSTritt | 110:a930767c281c | 15 | // Construct a timer object. | 
| CSTritt | 110:a930767c281c | 16 | Timer myTimer; | 
| CSTritt | 110:a930767c281c | 17 | |
| CSTritt | 110:a930767c281c | 18 | // Construct a transmit only serial connection over our USB. | 
| CSTritt | 110:a930767c281c | 19 | Serial pc(USBTX, NC, 9600); | 
| CSTritt | 110:a930767c281c | 20 | |
| CSTritt | 109:b061f9830736 | 21 | int main() | 
| CSTritt | 109:b061f9830736 | 22 | { | 
| CSTritt | 110:a930767c281c | 23 | myTimer.start(); // Start the timer. | 
| CSTritt | 110:a930767c281c | 24 | |
| CSTritt | 109:b061f9830736 | 25 | while(true) { // Main loop. | 
| CSTritt | 110:a930767c281c | 26 | if (myButton == 0) { // Button is pressed (active low). | 
| CSTritt | 110:a930767c281c | 27 | // Save the time on timer. | 
| CSTritt | 110:a930767c281c | 28 | int firstTime = myTimer.read_us(); | 
| CSTritt | 110:a930767c281c | 29 | int secondTime = myTimer.read_us(); | 
| CSTritt | 110:a930767c281c | 30 | |
| CSTritt | 110:a930767c281c | 31 | // Send the time as text via the serial port. | 
| CSTritt | 110:a930767c281c | 32 | pc.printf("Time difference %i microseconds.\n", secondTime - | 
| CSTritt | 110:a930767c281c | 33 | firstTime ); | 
| CSTritt | 110:a930767c281c | 34 | |
| CSTritt | 110:a930767c281c | 35 | // Reset the timer. | 
| CSTritt | 110:a930767c281c | 36 | myTimer.reset(); | 
| CSTritt | 110:a930767c281c | 37 | |
| CSTritt | 110:a930767c281c | 38 | // Wait for the user to release the button. | 
| CSTritt | 110:a930767c281c | 39 | while(myButton == 0) { | 
| CSTritt | 110:a930767c281c | 40 | } | 
| CSTritt | 108:eee3167b25b4 | 41 | } | 
| CSTritt | 108:eee3167b25b4 | 42 | } | 
| CSTritt | 108:eee3167b25b4 | 43 | } |