a

Dependencies:   mbed

Revision:
0:d89d5712d45e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jun 04 09:02:38 2019 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+AnalogIn in(A0);
+
+/*#if !DEVICE_ANALOGOUT
+#error You cannot use this example as the AnalogOut is not supported on this device.
+#else*/
+AnalogOut out(PA_4);
+//#endif
+
+DigitalOut led(LED1);
+
+int main()
+{
+    printf("\nvong lap Analog\n\r");
+    printf("*** ket noi chan A0 va PA_4 voi nhau ***\n\r");
+    while(1) {
+        for (float out_value = 0.0f; out_value < 1.1f; out_value += 0.1f) {
+            // Giá trị đầu ra sử dụng DAC
+            out.write(out_value);
+            wait(0.1);
+            // doc ADC input
+            float in_value = in.read();
+            // DAC - ADC
+            float diff = fabs(out_value - in_value);
+            printf("(out:%.4f) - (in:%.4f) = (%.4f) \n\r", out_value, in_value, diff);
+            if (diff > 0.05f) {
+                printf("FAIL\n\r");
+            } else {
+                printf("\nOK\n\r");
+                 printf("\033[1A\n\r"); // di chuyen con tro len dong truoc do
+                // printf("DAC and ADC:");
+                 printf("(DAC out:%.4f) - (ADC in:%.4f) = (su khac biet giua hai gia tri: %.4f) \n\n\n\r", out_value, in_value, diff);
+               
+            }
+            led = !led; //nhap nhay led
+        }
+    }
+}
+