]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/analog_in/main.cpp
2 * Version of the Analog test,
3 * Intended for use by devices which
4 * don't have analog out.
6 * Connect 'control' to pin 21 of an mbed LPC1768
7 * Connect 'analogInput' to pin 18 of an mbed LPC1768
8 * Connect 'TX/RX' to pins 27 and 28 of an mbed LPC1768
14 #define ERROR_TOLERANCE 0.05
16 #if defined(TARGET_LPC1114)
18 AnalogIn
analogInput(dp4
);
19 DigitalOut
control(dp5
);
20 DigitalOut
indicator(LED1
);
26 uint8_t successes
= 0;
31 for (int i
= 0; i
< 10; i
++) {
33 float expectedValue
= i
* 0.1;
34 float value
= analogInput
.read();
36 if (value
> expectedValue
+ ERROR_TOLERANCE
|| value
< expectedValue
- ERROR_TOLERANCE
) {
38 printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL
, expectedValue
, value
, fabs(expectedValue
- value
));
41 printf("OK (out:%.4f) - (in:%.4f) = (%.4f)"NL
, out_value
, in_value
, diff
);
56 notify_success(false);