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.
Revision 0:cc014c610423, committed 2017-10-19
- Comitter:
- CSTritt
- Date:
- Thu Oct 19 21:05:11 2017 +0000
- Commit message:
- Initial version. Demonstrates use of header files and compilation units (files) for each function.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Oct 19 21:05:11 2017 +0000
@@ -0,0 +1,35 @@
+/*
+ Project: HeaderTest
+ File: main.cpp
+ Last revised by: Dr. C. S. Tritt
+ Last revision on: 9/19/17 (v. 1.0)
+
+ Repeatedly toggles on-board LED.
+
+ This example code is in the public domain.
+*/
+// Use #include directives to "paste" text from other files into your code.
+// Use this #include to declare all the mbed driver classes. The mbed library
+// must also be added to the project either by importing it or by "Fixing" the
+// error that is generated when it has not been imported.
+#include "mbed.h"
+// Use this type of #include to include your own custom header files. Typically
+// 1 per project or library.
+#include <myProj.h>
+// Mbed driver class objects are typically declared and defined as global.
+DigitalOut board_LED(LED1);
+// Define global variables here.
+const float BASE_WAIT = 0.1;
+int cycles = 1;
+/* The "main" function defines your main program -- it executes as soon as
+ you program the board.
+*/
+int main() { // This curly brace marks the beginning of the main function.
+ board_LED = 0; // Initialize LED state (not necessary in this case).
+ while(true) { // while(true) repeat forever.
+ myStuff(); // Call function that is in its own file.
+ if (cycles == 11) { // Reset cycles after 10 of them.
+ cycles = 1;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 19 21:05:11 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myProj.h Thu Oct 19 21:05:11 2017 +0000 @@ -0,0 +1,17 @@ +/* + Project: HeaderTest + File: myProj.h + Last revised by: Dr. C. S. Tritt + Last revision on: 10/19/17 (v. 1.0) + + This is the header files for the HeaderTest project. It declares stuff that + will be used in/by multiple cpp files. +*/ +// Declare mbed objects. The extern indicates it is defined elsewhere (main.cpp +// in this case). +extern DigitalOut board_LED; +// Declare global variables (extern required to avoid errors). +extern const float BASE_WAIT; // Defined in main.cpp. +extern int cycles; // Defined in main.cpp. +// Declare your function(s. +void myStuff(void); // Defined in myStuff.cpp. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/myStuff.cpp Thu Oct 19 21:05:11 2017 +0000
@@ -0,0 +1,17 @@
+/*
+ Project: HeaderTest
+ File: myStuff.cpp
+ Last revised by: Dr. C. S. Tritt
+ Last revision on: 10/19/17 (v. 1.0)
+
+ This is the source file for the myStuff function. It toggles the LED.
+*/
+// See include comments in main.cpp and myProj.h.
+#include "mbed.h"
+#include <myProj.h>
+
+void myStuff(void) {
+ board_LED = !board_LED; // Toggle LED state.
+ wait(BASE_WAIT * (float) cycles); // Wait varying intervals.
+ cycles++; // Slowly slow down flash rate.
+}
\ No newline at end of file