Cortex Challenge Team / Mbed 2 deprecated Nucleo_read_analog_set

Dependencies:   mbed

Fork of Nucleo-Analog_read by Cortex Challenge Team

Revision:
5:a57d93f35f76
Parent:
4:da95e07f350a
--- a/main.cpp	Tue May 12 08:42:01 2015 +0000
+++ b/main.cpp	Tue May 12 09:06:50 2015 +0000
@@ -30,20 +30,20 @@
 #include "mbed.h"
 
 /* Defines -----------------------------------------------------------------------*/
-#define voltage 3300                        //voltage in mV, which is used in Nucleo kits
-#define mv(x)       ((x*voltage)/0xFFFF)    // raw value to value in mili volts
+#define voltage 3300                        //voltage in mV, used in Nucleo kits
+#define mv(x)       ((x*voltage)/0xFFFF)    // raw value to millvolts
 
 /* Function prototypes -----------------------------------------------------------*/
 
 /* Variables ---------------------------------------------------------------------*/
-int voltages =0;            //voltage to compare and start print
-bool start = true;          // if true it print value to serial
+int voltages =0;            
+bool start = true;          
 
 //mbed - initialization of peripherals
-AnalogIn analog_value(A0);      // inicialize analog input A0
-Serial pc(SERIAL_TX, SERIAL_RX);// inicialize Serial to connect to PC
-DigitalOut led(LED1);           // inicialize LED
-Ticker toggle_ticker;           // inicialize ticker
+AnalogIn analog_value(A0);      // initialize analog input A0
+Serial pc(SERIAL_TX, SERIAL_RX);// initialize Serial to connect to PC
+DigitalOut led(LED1);           // initialize LED
+Ticker toggle_ticker;           // initialize ticker
 
 /* Functions----------------------------------------------------------------------*/
 
@@ -58,13 +58,13 @@
 {
     int meas;
 
-    meas = analog_value.read_u16(); // Converts and read the analog input value (value from 0.0 to 0xFFFF)
-    meas = mv(meas);                // Change the value to be in the 0 to 3300 range
+    meas = analog_value.read_u16(); // Converts and reads the analog input value (value from 0.0 to 0xFFFF)
+    meas = mv(meas);                // Changes the value to be in the 0 to 3300 range (millivolts)
 
 
     led= !led;
-    if (meas > voltages ) { // If the value is greater than set voltage
-        start = true;       //start send data to Serial
+    if (meas > voltages ) {         // If the value is greater than set voltage
+        start = true;               //start send data to Serial
     }
     if(start) {
         while(!pc.writeable());     // wait to be serial available for sending data
@@ -74,7 +74,7 @@
 
 /***********************************************************************************
 * Function Name  : flushSerialPort.
-* Description    : Serial flush rountine.
+* Description    : Serial flush routine.
 * Input          : None.
 * Output         : None.
 * Return         : None.
@@ -98,17 +98,15 @@
     while(!pc.writeable()); // wait to be serial available for sending data
     pc.printf("HELP - MENU\n"); // send text to Serial
     while(!pc.writeable());
-    pc.printf("Data send to PC (numbers) are in mV.\n");
+    pc.printf("Data sent to PC are in millivolts(mV).\n");
     while(!pc.writeable());
-    pc.printf("Set data exactly.\n");
-    while(!pc.writeable());
-    pc.printf("Write to console: \"xx yy\", where xx is a code of seting and yy his value.\n");
+    pc.printf("Input format: \"xx yy\", where xx is the setting and yy is the value.\n");
     while(!pc.writeable());
-    pc.printf("01 y.yyy - set period[s] to send data to PC and start reading value, example:01 0.01\n");
+    pc.printf("01 y.yyy - set period [seconds] to send data to PC and start reading value, example: 01 0.01\n");
     while(!pc.writeable());
-    pc.printf("02 0 - stop reading value example:02 0\n");
+    pc.printf("02 0 - stop reading value, example: 02 0\n");
     while(!pc.writeable());
-    pc.printf("03 yyyy - Wait for minimum voltage[mV] (to 3299) and send data example:03 2000\n");
+    pc.printf("03 yyyy - Wait for minimum voltage [mV] (to 3299) and send data, example:03 2000\n");
     while(!pc.writeable());
     pc.printf("end HELP\n");
 }
@@ -123,14 +121,14 @@
 int main()
 {
     // variables to read from serials
-    int prijData=0;     // check if data are well set  
+    int prijData=0;     // check if data are set correctly  
     int Data1=0;        // first data from serial
     float Data2=0;      // second data from serial
 
-    pc.baud(115200);    //set speed of serial to 115200
+    pc.baud(115200);    //set serial speed to 115200
 
-    toggle_ticker.detach();             // do NOT call function
-    toggle_ticker.attach(&toggle, 1);   // 1 second was passed, call function toggle
+    toggle_ticker.detach();             //detach all functions from ticker
+    toggle_ticker.attach(&toggle, 1);   // 1 second passed, call function toggle
 
     pc.printf("\nAnalogIn example, data (numbers) are in mV.\n");
     menu(); //print menu
@@ -139,32 +137,32 @@
 
         //accepted data from serial
         prijData=pc.scanf("%d",&Data1);             // read number from serial
-        if(prijData==1 && (Data1>=1 && Data1<=3)) { // test if number was read and it is between 1 and 3
+        if(prijData==1 && (Data1>=1 && Data1<=3)) { // test if number was read and if it is between 1 and 3
             prijData=pc.scanf("%f",&Data2);         // read float number from serial
             if(prijData==1) {
                 prijData=2;         // set variable to set measure of values
             } else {
-                flushSerialPort();  // iscard data from serial
+                flushSerialPort();  // clear serial port, discard all data in the buffer
                 prijData=0;         // set variable to print menu
             }
         } else {
-            flushSerialPort();      // discard data from serial
+            flushSerialPort();      // clear serial port, discard all data in the buffer
             prijData=0;             // set variable to print menu
         }
 
         if(prijData==2) {
             if(Data1==1) {                              // change time to call function toggle
-                toggle_ticker.detach();                 // do NOT call function
+                toggle_ticker.detach();                 //detach all functions from ticker
                 toggle_ticker.attach(&toggle, Data2);   // Data2 seconds was passed, call function toggle
             } else if(Data1==2) {                       // stop call function toggle
-                toggle_ticker.detach();                 // do NOT call function
+                toggle_ticker.detach();                 //detach all functions from ticker
             } else if(Data1==3) {                       //set variables, which are use in toggle
                 voltages=(int)Data2;
                 start = false;
             }
         } else {
             menu();             // print menu
-            flushSerialPort();  // discard data from serial
+            flushSerialPort();  // clear serial port, discard all data in the buffer
 
         }
     }