Reads Analog and sends to the computer every 0.01 seconds.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Jamess
Date:
Tue Feb 24 23:06:58 2015 +0000
Commit message:
Hello Everybody.; My first published program, works perfectly so far =); I am going to use the FRDM KL 25z in order to measure an analog flux sensor and an acelerometer. This is the flux sensor part.; If you guys have any hints, I would like to hear.; TY

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1b42934fe1a1 main.cpp
--- /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
diff -r 000000000000 -r 1b42934fe1a1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 24 23:06:58 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file