jongrock chun / Mbed 2 deprecated For_test_code

Dependencies:   mbed

Fork of AnalogIn_HelloWorld_WIZwiki-W7500 by IOP

Revision:
9:21193ec77fbf
Parent:
8:bc6291805741
--- a/main.cpp	Wed Feb 03 07:27:16 2016 +0000
+++ b/main.cpp	Tue Oct 23 08:39:16 2018 +0000
@@ -1,44 +1,85 @@
 /* Analog Input Example Program */
- 
+
 #include "mbed.h"
 
-DigitalOut myled_R(LED_RED);
+AnalogIn mic(A0);
+PwmOut aout(D3);
+InterruptIn trigger_i(D15);
+PwmOut trigger_o(D14);
+//PwmOut test(D5);
+DigitalOut toggle1 (D0);
+DigitalOut toggle2 (D1);
+
+#define MAX_BUF_SIZE 128
+//char buf0[MAX_BUF_SIZE];
+char buf1[MAX_BUF_SIZE];
+char buf0[MAX_BUF_SIZE];
+int i = 0;
+char buf_sel = 1;
+int n;
+float out;
+
+void adcTickfunc() 
+{
+    if(buf_sel==1){
+        for(i=0;i<128;i++){
+            buf0[i] = mic.read_u16() >> 4;
+            i++;
+            toggle1 = !toggle1;
+            printf("input progress... \n\r");
 
-AnalogIn ain(A0);     
+            if (i==MAX_BUF_SIZE){
+                buf_sel = 0;
+                i=0;
+                printf("end \n\r");
+                toggle1 = 0;
+                }
+            }
+    }
+    
+    else if(buf_sel==0){
+        for(i=0;i<128;i++){
+            aout.write((float)buf0[i]/256*1.32);
+            i++;
+            printf("output progress... \n\r");
+            if (i==MAX_BUF_SIZE){
+                buf_sel = 1;
+                i=0;
+                printf("end \n\r");
+                toggle2 = !toggle2;
+                }
+        }
+    }
+}
+/*
+    if (buf_sel) aout.write((float)buf1[i]/256);
+    else         aout.write((float)buf0[i]/256);
+    i++;
+    
+    //if (i == MAX_BUF_SIZE) i = MAX_BUF_SIZE - 1;
+
+if (buf_sel == 0) buf0[i] = mic.read_u16() >> 4;
+    else          buf1[i] = mic.read_u16() >> 4;
+    i++;
+    
+    if (i == MAX_BUF_SIZE) { 
+        i = 0;
+        //toggle = !toggle;
+        if (buf_sel) buf_sel = 0; else buf_sel = 1;
+    }*/
 
 
-int main(void)
-{   
-    int ain_val = 0;
-    
+int main() 
+{
+    printf("Hello!\n\r");
+    printf("Start the communication \n\r");
+    trigger_i.rise(&adcTickfunc);
+
     while (1) {
-        
-        ain_val = ain.read()*1000;
-            
-        // Compare between 'Specific value' and 'Analog Input value'
-        if(ain_val > 500)  
-        {
-            myled_R = 1;      // Red LED OFF
-        }
-        else    
-        {
-            myled_R = 0;      // Red LED ON
+        trigger_o.period_us(100);
+        trigger_o.write(0.5);
+        //aout.period_us(50);
+        //test.period(10);
+        //test.write(50);
         }
-        
-        // output the voltage and analog values
-        printf("======================\r\n");
-        printf("voltage value : %3.3f\r\n", ain.read()*3.3f);   // voltage 0.0V ~ 3.3V
-        printf("analog value : %3.3f\r\n", ain.read());         // analog value 0.0 ~ 1.0
-        printf("analog value x1000 : %d\r\n",ain_val);          // analog value 0 ~ 1000
-        wait(1.0);
-    }
 }
-
-
-
-
-
-
-
-
-