This simple program enable LPC11U24 MBED board to act as a simple integer calculator. Just type the operation you want to execute from the serial terminal. Admitted operations: +, -, * /, ^ (only positive exponent). Multiple operations in raw are supported as well as negative integer.

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

Revision:
5:8bb67df511a3
Parent:
4:235e50314809
--- a/main.cpp	Mon Sep 22 06:27:25 2014 +0000
+++ b/main.cpp	Mon Sep 22 06:32:31 2014 +0000
@@ -13,10 +13,6 @@
     for ( int i= (size -1); i >= 0 ; i-- ) {
         tmp = int( tmp + ( ( int(char_p[i]) - 48 ) * pot_ten ));
         pot_ten*=10;
-        //pc.printf("\n");
-        //print_num(tmp);
-        //pc.printf("\n");
-        //print_num(pot_ten);
     }
     return tmp;
 }
@@ -42,6 +38,7 @@
     }
 }
 
+//global variables
 char c;
 char op = '=';
 char operand [100];
@@ -55,8 +52,7 @@
 bool neg_operand = FALSE;
 bool error=FALSE;
 
-
-// serial interrup callback function
+// serial interrupt callback function
 void callback()
 {
     while(1) {
@@ -86,10 +82,10 @@
                 }
 
 
-                if (first) {  //First Operator
+                if (first) {  //First operator
                     result = ioperand;
                     first = FALSE;
-                } else { //Do Calculation
+                } else { //Do calculation
 
                     if(op == '+') {
                         result = int (result + ioperand);
@@ -125,7 +121,7 @@
                         error = FALSE;
                     }
                 }
-                op = c;  // assign the Operator
+                op = c;  // assign the operator
                 index=0; // reset the operand
                 sign_check = TRUE; // sign check activated
                 neg_operand=FALSE;
@@ -146,6 +142,7 @@
     }
 }
 
+// MAIN
 int main()
 {
     pc.attach(&callback,Serial::RxIrq);