]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/analog_in/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / mbed / analog_in / main.cpp
1 /*
2 * Version of the Analog test,
3 * Intended for use by devices which
4 * don't have analog out.
5 *
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
9 *
10 * Upload:
11 */
12 #include "test_env.h"
13
14 #define ERROR_TOLERANCE 0.05
15
16 #if defined(TARGET_LPC1114)
17
18 AnalogIn analogInput(dp4);
19 DigitalOut control(dp5);
20 DigitalOut indicator(LED1);
21
22 #else
23
24 #endif
25
26 uint8_t successes = 0;
27
28 int main() {
29 control = 0;
30
31 for (int i = 0; i < 10; i++) {
32 // Read value,
33 float expectedValue = i * 0.1;
34 float value = analogInput.read();
35
36 if (value > expectedValue + ERROR_TOLERANCE || value < expectedValue - ERROR_TOLERANCE) {
37 // Failure.
38 printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL, expectedValue, value, fabs(expectedValue - value));
39 }
40 else {
41 printf("OK (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
42 successes++;
43 }
44
45 control = 1;
46 indicator = 1;
47 wait(0.1);
48 control = 0;
49 indicator = 0;
50 }
51
52 if (successes > 8) {
53 notify_success(true);
54 }
55 else {
56 notify_success(false);
57 }
58 }
Imprint / Impressum