Nam
main.cpp
- Committer:
- nhancap98
- Date:
- 2019-06-10
- Revision:
- 0:fe978a0a248e
File content as of revision 0:fe978a0a248e:
#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 } } }