Nam
Diff: main.cpp
- Revision:
- 0:fe978a0a248e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jun 10 11:16:18 2019 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + +AnalogIn in(A0); +AnalogOut out(PA_4); +DigitalOut led(LED1); +int main() +{ + printf("\n Vong 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? d?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 + } + } +} +