Reads Analog and sends to the computer every 0.01 seconds.

Dependencies:   mbed

Revision:
0:1b42934fe1a1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 24 23:06:58 2015 +0000
@@ -0,0 +1,67 @@
+// Sending Serial Values Read from AnalogIN
+// by Thiago Rech
+//
+//   When receiving the number '2', starts reading and sending the analog voltage in a 100Hz frequency*
+//
+// This is the first mbed project that I publish =D I would be thankfull if anyne give tips and point mistakes if any.
+
+
+#include "mbed.h"
+
+AnalogIn ain(PTB3);
+DigitalOut led2(LED2);  // Led red
+Ticker t1;              // Timer to send data
+Serial pc(USBTX, USBRX);
+
+void HandlerT1(void);
+void rx_Handler(void);
+
+volatile bool STATUS = true;
+char test = 0;
+
+int main()
+{
+
+    //Setup
+    pc.baud(9600);
+    pc.printf("Press 2 to Start");
+    pc.attach(&rx_Handler, pc.RxIrq);
+    led2=0;
+
+    while(1) {
+
+        wait(0.5);                                  // Debug
+        led2 = 0;
+        pc.putc(test);                             // Debug
+
+        if (teste == '2') {
+            t1.attach(&HandlerT1, 0.01);
+        }
+
+        while(test == '2') {
+
+            if (STATUS == true) {
+
+                STATUS = false;
+                led2 = 1;
+                pc.putc(analogValue);
+                pc.printf("0x%04X",ain.read_u16());
+            }
+
+
+        } //end of while(test=='2'){}
+
+        t1.detach();    // Detaches timer interruption when not needed
+    }//end of while(1)
+}//end of main
+
+void HandlerT1(void)
+{
+    STATUS = true;
+}
+
+void rx_Handler(void)
+{
+    test = pc.getc();
+    pc.putc(test);
+}
\ No newline at end of file