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.
Diff: main.cpp
- Revision:
- 110:22b71c32c5e1
- Parent:
- 109:b061f9830736
- Child:
- 111:956b1c606b66
diff -r b061f9830736 -r 22b71c32c5e1 main.cpp
--- a/main.cpp Fri Oct 01 02:45:38 2021 +0000
+++ b/main.cpp Fri Oct 01 03:03:36 2021 +0000
@@ -1,29 +1,27 @@
/*
-Project: 21_Button-v5
+Project: 21_TimerTest1_v5
File: main.cpp
-
-Toogles LED1 when USER_BUTTON is tapped. Note LED1 is also PA_5 which is
-also D13. Based on built-in mbed example Nucleo_read_button. Holding the button
-down will result in LED flashing.
-
-Modified 12 Aug 2017 by Dr. Sheila Ross
-Last revised 9/30/21 by Dr. C. S. Tritt
+
+Explores timer behavior. Each loop takes about 24 mS. Most of this time is
+likely spent doing the serial output.
+
+Last modified 9/30/21 by C. S. Tritt (v. 1.0)
*/
-
#include "mbed.h"
-// Construct a digital input linked to the USER_BUTTON.
-DigitalIn myButton(USER_BUTTON); // Built in blue button.
-
-// Construct a digital output linked to LED1.
-DigitalOut myLed(LED1); // Built-in green LED.
-
+// Construct a timer object.
+Timer myTimer;
+// Construct a transmit only serial connection over our USB.
+Serial pc(USBTX, NC, 9600);
+
int main()
{
- while(true) { // Main loop.
- if (myButton == 0) { // Button is active low.
- myLed = !myLed; // Toggle LED on/off.
- ThisThread::sleep_for(100); // Avoid double-tap, 0.1 seconds.
- }
+ myTimer.start(); // Start the timer.
+
+ for (int i = 1; i <= 20; i++) { // Main loop.
+ // Save the time on timer.
+ float current_time = myTimer.read();
+ // Send the time as text via the serial port.
+ pc.printf("Time %f seconds.\n",current_time );
}
}
\ No newline at end of file