Charles Tritt / Mbed 2 deprecated GlobalExample

Dependencies:   mbed

Fork of FunctionExample by Charles Tritt

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Thu Oct 05 03:00:57 2017 +0000
Parent:
1:8a2fb22f43f3
Commit message:
Initial version.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 03 18:05:17 2017 +0000
+++ b/main.cpp	Thu Oct 05 03:00:57 2017 +0000
@@ -1,20 +1,23 @@
 /*
-Project: FunctionExample
+Project: Global Example
 File: main.cpp
 
- This simple program demonstrates that C passes arguments by value.
- See http://www.csie.ntu.edu.tw/~r92094/c++/VT100.html for escape sequences.
+ This simple program demonstrates C global variables with file scope.
+ See http://ascii-table.com/ansi-escape-sequences-vt-100.php for sequences.
  
- Written by: Dr. C. S. Tritt; Last revised 10/3/17 (v. 1.0)
+ Written by: Dr. C. S. Tritt; Last revised 10/4/17 (v. 1.0)
 */
 #include "mbed.h"
 
 int myFunc(int x, int y); // Function declaration required.
 
+const float myFactor = 3.3; // Arbitrary factor. Unitless. Move around.
+const char ESC=27; // Define escape character for escape sequence.
+
 int main() {
     while(true) {
-        const char ESC=27; // Optional - Define escape for escape sequence.
-        printf("%c[2J", ESC); // Optional - VT100 clear screen escape sequence.
+        printf("%c[2J", ESC); // Optional - ANSI/VT100 clear screen sequence.
+        printf("%c[H", ESC); // Optional - ANSI/VT100 cursor home.
         printf("In function demo main...\n");        
         int a = 5; // Create and initialize a.
         printf("a = %d\n", a); // Display a.
@@ -23,19 +26,12 @@
         printf("About to call my function.\n");
         int c = myFunc(a, b); // Call my function.
         printf("Function has returned.\n");
-        printf("a = %d\n", a); // Redisplay a.
-        printf("b = %d\n", b); // Redisplay b.               
         printf("c = %d\n", c); // Display b.
         wait(2.0f); // Pause for a second.
     }
 }
 
-int myFunc(int x, int y) { // Function definition. Often in seperate files!
-    int z = x + y;
-    // Changing parameter values here won't change argument values in main!
-    x = 50;
-    printf("x = %d\n", x); // Generally don't put I/O in regular functions.
-    y = 100;
-    printf("y = %d\n", y); // Generally don't put I/O in regular functions.
+int myFunc(int x, int y) { // Function definition. Often in separate files!
+    int z = (x + y)/myFactor;
     return z; // Explicit return is required in C/C++. 
-}    
\ No newline at end of file
+}
\ No newline at end of file